Manipulating the keyboard buffer

All aspects of programming on the Commander X16.
Post Reply
Martin Schmalenbach
Posts: 140
Joined: Tue Jul 21, 2020 10:08 pm

Manipulating the keyboard buffer

Post by Martin Schmalenbach »

Hi

I'm having trouble making this work - it's taken from a very similar program by Ian Sinclair for the C64 in BASIC V2.

The program is designed to delete a block of lines from a BASIC program.

The only changes I've made are to the poke locations for the keyboard buffer etc. These changed poke locations were found by digging through the appropriate .SYM files that come with the emulator.

When you run the program with

Code: Select all

RUN 63900
the screen clears, asks you to enter the start & stop line numbers of lines in your BASIC code you wish to delete, and it deletes them for you by clearing the screen, and then repeatedly putting 4 RETURN chars in to the keyboard buffer, printing the line number of the next line to delete, keeping it as blank, and then below it printing a new entry for line 63940 and below that the command

Code: Select all

GOTO 63940
then the SYS 50876 calls the routine in the BASIC ROM that is effectively a warm start that executes the commands in the keyboard buffer.

Code: Select all

63900 CLS:INPUT "ENTER START,STOP LINE NOS:",S,F:CLS 
63910 PRINT CHR$(19)S:S=S+10:IF S>F+10 THEN 63960 
63920 PRINT "63940 S=";S;" :F=";F:PRINT "GOTO 63940" 
63930 POKE 43008,19:FOR N=43009 TO 43011:POKE N,13:POKE 43018,4:NEXT:SYS 50876 
63940 REM DUMMY LINE 
63950 GOTO 63910 
63960 POKE 43018,0:CLS:END
Any pointers or other help gratefully accepted.
Stefan
Posts: 465
Joined: Thu Aug 20, 2020 8:59 am

Re: Manipulating the keyboard buffer

Post by Stefan »

Just reading the code, I come to think of two things.

The first is that access to banked RAM on line 63930 and 64960 isn't guaranteed to use RAM bank 0. In fact, BASIC by default uses RAM bank 1 after power-on. To change RAM bank you need to use the new BANK statement implemented in X16 BASIC.

The second is that it's not recommended that you POKE or PEEK directly into KERNAL or BASIC variables, as they are not guaranteed to remain unchanged or in the same location between KERNAL revision.

It would be safer to call the KERNAL function kbdbuf_put which lets you add characters to the queue.
Martin Schmalenbach
Posts: 140
Joined: Tue Jul 21, 2020 10:08 pm

Re: Manipulating the keyboard buffer

Post by Martin Schmalenbach »

Hi Stefan

Thanks for that additional & valuable perspective & info - I shall go play!

Cheers

Martin
Post Reply