Welcome, Guest. Please login or register.


Author Topic: Enterprise C compiler for PC (Read 18636 times)

Offline lgb

  • EP addict
  • *
  • Posts: 3550
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux (Ubuntu) Linux (Ubuntu)
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
    • http://lgb.hu/
Re: Enterprise C compiler for PC
« Reply #30 on: 2015.August.24. 11:50:06 »

Offline Alcoholics Anonymous

  • Newbie
  • Posts: 10
  • Country: ca
  • OS:
  • Windows NT 6.2 Windows NT 6.2
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
    • Z88DK Homepage
Re: Enterprise C compiler for PC
« Reply #31 on: 2015.August.24. 18:34:48 »

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #32 on: 2015.August.24. 19:35:31 »
Hello. About the mouse I think is better to wait the first batch of Entermices to reach their new owners, but the mouse reading routine can be like this:


      ld   a, (INPUT_DEVICE) ; EXOS Variable 189
      cp   1
      jp   z, loc_C28F
      cp   2
      jp   z, loc_C294
;modification here
      cp   5
      jp   z, loc_C285    ; Serial Mouse Systems is merged with the internal Joystick
      cp   6
      jp   z, loc_C285      ; Serial Mouse Systems WILL be merged with the internal Joystick
;end
      or   a
      jp   z, loc_C285
;Modification here
      ;Here begin the   Neos mouse reading
      ld   hl, X_REL   ; first   byte
      ld   a, 2      ; RTS low
      out   (0B7h),   a
      ld   b, 8      ; long delay
      call   WAIT
      call   READ_4BIT   ; read four higher bits
      rld         ; push them in (HL)
      xor   a      ; RTS high
      out   (0B7h),   a
      ld   b, 5      ; short   delay
      call   WAIT
      call   READ_4BIT   ; read four lower bits
      rld         ; push them in (HL)
      ld   hl, Y_REL   ; second byte
      ld   a, 2      ; RTS low
      out   (0B7h),   a
      ld   b, 5      ; short   delay
      call   WAIT
      call   READ_4BIT   ; read four higher bits
      rld         ; push them in (HL)
      xor   a      ; RTS high
      out   (0B7h),   a
      ld   b, 5      ; short   delay
      call   WAIT
      call   READ_4BIT   ; read four lower bits
      rld         ; push them in (HL)
                      ;<======Here will be added the future Wheel and three spare buttons reading. FIRST TENTATIVE
      ld   hl, SW_Z_STATUS
      ld   a, 2      ; RTS low
      out   (0B7h),   a
      ld   b, 5      ; short delay
      call   WAIT
      call   READ_4BIT   ; read four higher bits
      and 15
      cp 1         ; IF THIS NIBBLE=0001 THEN THE MOUSE IS IN EXTENDED PROTOCOL
      jr z, CONTINUE_READ
      xor   a      ; RTS high
      out   (0B7h),   a           ;IGNORE THAT NIBBLE
                             ld (hl), 0. ; we don't need old values
      jr STOP_READ
      
CONTINUE_READ:
      xor   a      ; RTS high
      out   (0B7h),   a
      ld   b, 5      ; short   delay
      call   WAIT
      call   READ_4BIT   ; read four higher bits, the three lower bits are the buttons. They come ready to store
      push af      ; push them in stack. they are in the lower nibble.
      ld a, (hl);
                             push af   ;save the Z counter for later.
      ld   a, 2      ; RTS low
      out   (0B7h),   a
      ld   b, 5      ; short   delay
      call   WAIT
      call   READ_4BIT   ; read four bits
      rld         ;we need z displacement in 8 bit
      xor   a      ; RTS high
      out   (0B7h),   a
      ld   b, 5      ; short   delay
      call   WAIT
      call   READ_4BIT   ; read four lower bits. Z displacement
      rld         ; push them in (HL)   ;NOW WE HAVE Z displacement in (hl)
      pop af         ; restored Z counter to "a", but we have garbage on high nibble   
                             and 00Fh
                             bit 3, a
                             jr z, SIGN_DONE
                             or 0F0h
 SIGN_DONE:                                               ; now we have the sign extended to 8 bits on "a"
                             add a, (hl)
                            cp 128                              ;positive or negative?
                             jr c, POSITIVE
                             cp 248                             ;lower than -8?
                              jr nc, FINISHED             ;
                              ld a, 248                          ; -8 is the bottom
                              jr FINISHED
POSITIVE:
                              cp 8                                 ;higer than 7?
                              jr c, FINISHED
                              ld a, 7                             ; 7 is the top
FINISHED:                                                  ; the excess  of 7 or -8 has been wipped
                              ld c, a                            ;save Z addition on c
                              pop af                            ; retrieve the buttons status. They are now on first nibble of a
                              rld                                  ;buttons stored
                              ld a, c                           ;we only need the first nibble of Z counter addition
                              rld                                 ; the spare buttons status and the Z counter are now in SW_Z_STATUS
STOP_READ:
      xor   a                       ;recall buttons on row 0
      out   (0B5h),   a
      in   a, (0B6h)   ; read Mouse buttons
      and 7      ;mask
      xor 7      ;flip them all as on Enterprise a pressed key is 1 and released 0
      rl (hl)    ;Get ready the bit 7 of "hl" register pair. Inside is SW_Z_STATUS, variable number 190
      srl a   ; This is the very FIRST "srl a". The button status is now in the carry flag
            ; secondary button of Boxsoft is read on J column. Primary button of Entermice is read on K column
      push af
      ld   a, (INPUT_DEVICE)
      cp 3   ;Boxsoft interface mode buttons   
      jr nz, L_BUTTON     
      pop af  ; We need the value of "a" and "f" registers. Carry flag still stores the value of secondary button
      rr (hl) ;secondary button goes to bit 7 of SW_Z_STATUS, variable number 190
      srl a   ; Primary button of Boxsoft is on J column. This is the second "srl a"
      JR MAIN_BUTTON
L_BUTTON:   ;Entermice interface mode buttons
      pop af  ;retrieve the value of register "a". "f" is disposable, soon we will load the button on carry flag
      push af ; I still will need later the register "a" value
      srl a  ; two "srl a" because the secondary button of Entermice is read on L column
      srl a  ; the proper button status is now in the carry flag
      rr (hl) ;secondary button goes to bit 7 of SW_Z_STATUS, variable number 190
      pop af  ;retrieve the value of register "a" just after the FIRST "srl a"
MAIN_BUTTON:
      and 1
      ld   (FIRE_STATUS), a ; EXOS   Variable 188. K column if Boxsoft or L column if Entermice
      call   sub_C3A6   ; this is the "corrections and drawing" routine where the "velocity" 1.1 modification was made
      ld   a, (X_REL)
      ld   c, a
      ld   a, (Y_REL)
      or   c
      ret
   ;end   



;-------------------------------------
WAIT:               
      nop
      nop
      nop
      dec   b
      jr   nz, WAIT
      ret
      ;end
;-----------------------------------------


READ_4BIT:            
      ld   b, 4
      ld   d, 0
      ld a, (INPUT_DEVICE)
      cp 3
      jr z, L_COLUMN
      
K_COLUMN:            
      ld   a, b
      ;inc   c ;    this is not necessary
      out   (0B5h),   a
      in   a, (0B6h)
      ld c, a
      rra         ;data read from K column
      rra
      rl   d
      djnz   K_COLUMN
      jr CONTINUE

L_COLUMN:            
      ld   a, b
      ;inc   c ;    this is not necessary
      out   (0B5h),   a
      in   a, (0B6h)
      ld c, a
      rra         ;data read from L column
      rl   d
      djnz   L_COLUMN

CONTINUE:
      ld   a, d
      ret
;end



----------------------------

Ovserve, the old mouse type is INPUT_DEVICE=3. The new standard is INPUT_DEVICE=4.

I'm already working in this routine and some aspects need to be tested on a real Enterprise.

« Last Edit: 2015.September.06. 08:57:29 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #33 on: 2015.August.24. 19:49:43 »
X_REL               x axis displacement since last reading, 8 bits signed
Y_REL.              Y axis displavement since last reading, 8 bits signed
FIRE_STATUS.  main mouse button
SW_Z_STATUS  high nibble: bit 7 = secondary mouse button, bits 4, 5 and 6 spare buttons
                           Low nibble Z displacement counter, 4 bits signed
                                 
« Last Edit: 2015.August.27. 00:59:16 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #34 on: 2015.August.24. 20:30:54 »
The mouse is read every 50 Hz  by interrupts.

The reading of the mouse is triggered by putting RTS low for  a long pause. Then the mouse sends the first nibble.
RTS is put high for a short pause and the mouse sends the second nibble.
RTS is put low for a short pause and the mouse sends the third nibble.

And so on. Two nibbles make a byte. Two bytes are read if we have a legacy mouse, but upto four if in extended mode.
« Last Edit: 2015.August.24. 20:40:02 by gflorez »

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #35 on: 2015.August.24. 20:38:00 »
The control ports of the Enterprise are only for reading keypresses, for inputs, so it is needed an output signal in order to comunicate with the mouse.

The solution is to use the RTS pin signal from the underused serial port.

Offline Alcoholics Anonymous

  • Newbie
  • Posts: 10
  • Country: ca
  • OS:
  • Windows NT 6.2 Windows NT 6.2
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
    • Z88DK Homepage
Re: Enterprise C compiler for PC
« Reply #36 on: 2015.August.25. 18:06:19 »

Offline pear

  • EP lover
  • *
  • Posts: 819
  • Country: pl
  • Z80 only
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #37 on: 2015.August.25. 18:23:28 »
Maybe timings will help you understand more.
The mouse is polled after each interruption of video (IRQ 50Hz) (answer later in the same thread).

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #38 on: 2015.August.25. 20:49:16 »
What I've shown you above  are modifications done to an old driver from the 80's. It was part of a third party product named Boxsoft mouse interface bundled as a paint program. The creator assured here in this page that he only sold about 100 units.

It consisted on an adapter that implemented a standard d9 joystick port on the Enterprise, a Neos mouse, the Paintbox program and the driver itstelf.

It worked like a conventional modern mouse, but lacked velocity(acceleration). In the last modification made by the author he introduced a fix that doubled the amount of movement when greater than 1 or -1 pixels.

That  "corrections and drawing" call is not important for you as you will draw the pointer with your own routines, I think.

But now the interface has evolved to avoid some incompatibilities with programs that expect a joystick on that port.

Now  the mouse status is read on some undocumented possible switchs on the same controller port.

Also, it has been discovered that the Neos mouse is in reality a modified Msx mouse. So a Msx to ps2 mouse converter has been added to the interface. The name of the interface evolution is Entermice.

Meanwhile Prodatron, the creator of the superb multiplatform operative system named SymbOs, has made a port for the Enterprise. One of the target platforms is Msx and he has expanded its mouse protocol to manage ps2 mice(by Msx to ps2 adapter) with up to 5 buttons and wheel. He can apply easily that mouse protocol expansion also to the Enterprise port if there is already a hardware supporting it.

I have to say that ps2 mice have certain velocity in its circuits, so the feel now is almost exactly as a modern mouse.


All that improvements are included in that little routine....


Abut the timming of the delays.... They don't need to be accurate. Only the first delay is important. Then the mouse or the converter watch for all the readings done in a fixed total time.
« Last Edit: 2015.August.27. 00:56:24 by gflorez »

Offline lgb

  • EP addict
  • *
  • Posts: 3550
  • Country: hu
  • æðsta yfirmaður
  • OS:
  • Linux (Ubuntu) Linux (Ubuntu)
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
    • http://lgb.hu/
Re: Enterprise C compiler for PC
« Reply #39 on: 2015.August.26. 00:19:39 »
I was glancing through http://ep.homeserver.hu/Dokumentacio/Konyvek/EXDOS/EXDOSeng.htm but I can see now it is mentioned that the disk channel is only opened and closed if you're loading / saving without first opening a channel.  There's no mention of seeking or random access of files.  It's just a simple reference for basic so there isn't a lot of meaty information there.  I found a reference to ISDOS on the same site (in Hungarian) which seems to have a lot more information and makes it look like ISDOS has a lot in common with cpm.  But of course ISDOS is an extension / replacement of EXDOS.

IS-DOS is written by IS (Intelligent Software) to be compatible with CP/M, so it's a CP/M in some way, but not the from the original BDOS from DR. If I remember correctly, it's compatible with CP/M version 2.2 (at least if I remember correctly, I wrote a small CP/M program to get CP/M version and then print it, and it was 0x22). It does not replace EXDOS/EXOS, but it's another layer "built top on them". So some even name iS-DOS as "the CP/M for EP" too. This means several things, for example something I've already mentioned: it uses EXDOS, thus its native file system (FAT12) with all the directory etc stuff which was not possible with a "real" CP/M 2 (if I remember correctly) only maybe in later CP/M versions (?). Once I found the disassembled BDOS source is available (well, as far as I remember, know even "officially" available?), it was quite trivial try from me, to write a stupid and short CBIOS for EP, so of  course the "original" CP/M from DR can run on EP too, but still, IS-DOS is hard to beat, because you can also use the good things for EXDOS too with it (or even EXOS commands are available from IS-DOS too directly). Native CP/M BDOS implements some file system (I don't know it too much) which sounds a horror for me, eg almost as many exact formats (especially sector "skews" and similar things) exists as CP/M platforms :shock: I just "had to" mention these as you wrote "it looks like ISDOS has a lot common with cpm". Well, no wonder, because IS-DOS is "the CP/M" for EP with extra stuffs :) Though I am not so familiar with IS-DOS to tell, if there are major/minor compatibility issues compared with a DR CP/M BDOS system ... My personal opinion only: I think CP/M compatibility was a design concept for EP, even EXDOS has some notions (without IS-DOS too, in once) to be quite similar to CP/M maybe for easier IS-DOS CP/M implementation then. Again: if I remember correctly when once I tried to dig into EXDOS a bit :)

Quote
There's no mention of seeking or random access of files.

Hmm, maybe because some should use EXOS for that (opening, then reading/writing channel, set channel status call - which allows seeks etc). EXOS internally of course will use EXDOS if the channel refers for a file on a disk, and not some other entity, like a DISPLAY: channel (which is not so much seekable of course, for example).

About your C code examples, FILE* stuffs, etc: well, as far as I can see, my views on this topic are somewhat different. Your approach is about the correct ("C standard") implementation which of course is the better one. I usually have the habit to "ignore" this (well ...) since I often feel it gives too much complexity for a 8 bit system with limited resources. I must admit, my viewpoint is not so nice at all :) I should not comment these topics further, since it seems you are quite good in it already :)

Quote
Another question about the keyboard:  is there a list of standard ascii codes for keypresses returned by the EP firmware somewhere?  I'm not sure what to do about returning ascii codes for ALT keys and some special keys.  I realize the function keys are macros on the EP but in the c lib it's lower level so there is no macro expansion and key codes would have to be returned.

Maybe this can help?

http://ep.homeserver.hu/Dokumentacio/Konyvek/EXOS_2.1_technikal_information/exos/keyboard/Ch2.html

About function keys: I am not sure about that, of course, they are just keys like others, just maybe EXOS "translates" the keypresses for the programmed string as 'faked keypresses' (or such) when a function key is pressed?

http://ep.homeserver.hu/Dokumentacio/Konyvek/EXOS_2.1_technikal_information/exos/keyboard/Ch3.html

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #40 on: 2015.August.27. 01:14:06 »
Yes, there are different CPU clocks, hardware modifications, not from stock, but the compensation for that variations  is planned to be made by the firmware MCU inside the adapter.

The entermice wil be a complex piece of hardware, firmware and software mix.

Offline Alcoholics Anonymous

  • Newbie
  • Posts: 10
  • Country: ca
  • OS:
  • Windows NT 6.2 Windows NT 6.2
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
    • Z88DK Homepage
Re: Enterprise C compiler for PC
« Reply #41 on: 2015.August.27. 04:07:16 »

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #42 on: 2015.August.27. 09:22:23 »
Yes, you can load the mouse driver or not. It is not in Rom. It works as an extension to Exos:

https://enterpriseforever.com/programming/universal-mouse-driver/?action=dlattach;attach=13253

You can load it directly from Basic or Exos. Then to initialize it you must execute ":pb".

As you don't own a mouse interface you can try the internal joystick.

Once loaded the driver and initialized, this little Basic program will set the system for you and will open the required channels:

100 PROGRAM "mouse_test.bas"
110 GRAPHICS ! Usually the video channel is number £101:
120 SET 189,0 !  internal joystick as input device
130 SET 180,101 ! Video channel to put the mouse on. Only graphics.
140 SET 183,255 ! Colour of the pointer
150 OPEN £1:"mouse:" ! Opens a channel on the mouse device

Move the keyboard joystick to see the effect. Observe that the Basic program has ended.


« Last Edit: 2015.August.27. 10:01:21 by gflorez »

Offline Zozosoft

  • EP addict
  • *
  • Posts: 14121
  • Country: hu
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
    • http://enterprise.iko.hu/
Re: Enterprise C compiler for PC
« Reply #43 on: 2015.August.27. 09:27:41 »
Yes, you can load the mouse driver or not. It is not in Rom.
Currently :-)

Offline gflorez

  • EP addict
  • *
  • Posts: 3261
  • Country: es
  • OS:
  • Unknown Unknown
  • Browser:
  • Firefox 40.0 Firefox 40.0
    • View Profile
Re: Enterprise C compiler for PC
« Reply #44 on: 2015.August.27. 10:14:35 »
Hello Zozo. How it can be done, allocating memory and placing there the "modifiable" memory section?