ML routine for polling 542 keyboard

Post Reply
lowrybt1
Posts: 135
Joined: Sun Mar 08, 2015 3:42 pm

ML routine for polling 542 keyboard

Post by lowrybt1 » Sat May 18, 2019 4:43 am

Does anyone know a source for a published USR ML routine for polling the 542 keyboard that works under 65Dv3.3? I'm updating a BASIC lunar lander game I coded back in the day.

Thanks, Tom
C4PDF w. 24K, 2 x 5.25 MPI B-51 drives
C1P RevB with fully-populated 610 board and A-13. Klyball D-13.
Spares: 600 Rev.D, 610 board, 540A, A-13 with homebuilt data separator, MPI B-51 logic board (w/o data sep module) and mechanicals

dave
Site Admin
Posts: 560
Joined: Tue Sep 09, 2008 5:24 am

Re: ML routine for polling 542 keyboard

Post by dave » Sat May 18, 2019 8:58 pm

I'm not sure about a machine ready listing, but the June 1984 issue of Peek(65) has a commented disassembly of the ROM polled 542 keyboard routine:

http://osiweb.org/Peek65/Peek65_V5N6-06_1984.pdf

There is a ROM entry point you can call that runs the poll loop only once rather than wait for a key press.

The Software Consultants OS65D v3.2 disassembly manual has this to say about the way OS65D uses the ROM keyboard routine:
THIS ROUTINE USES THE SAME ROUTINE AS THE ROM BASED MACHINES. UNFORTUNATELY, THE DISK BASIC USES SOME OF THE SAME MEMORY LOCATIONS AS THE ROUTINE AT $FD00. INSTEAD OF DOING THE CORRECT THING. WRITING A NEW ROUTINE FOR THE DOS, OSI MADE ANOTHER PATCH. EVERY TIME YOU INPUT FROM THE 540 KEYBOARD YOU MUST FIRST SWAP OUT 4 BYTES, CALL THE ROUTINE IN ROM @ $FD00, AND THEN RESTORE THE 4 BYTES. HIGHLY INEFFICIENT!
So perhaps you'd be better off starting with the ROM routine, relocating to RAM, and fix the scratch memory conflicts.

However, if you're only using a few keys, it might be easier to hard-code the poll:

1) write the latch to enable one row,
2) read the columns from the keyboard
3) just test the bits corresponding to the keys you care about in that row, and set a bit in a scratch register (1 bit per key)
4) repeat for all the rows containing keys you need for the game
5) load up the scratch register into the Accumulator (if less than 8 keys), or A and X registers (if less than 16 keys), and return.

For a game with left, right, thrust, quit and maybe a couple of other keys, you could use 1 byte to encode the results of a poll.

Dave

Post Reply