; ; BBCBasic for the pdp11 ; (C)J.G.Harston 1988 ; v0.00 22/03/89 Started writing ; v0.10 24/03/89 Displays message, gets to prompt ; ; NB: mov label,reg - relative value of label ; mov @#label,reg - absolute value of label org &0 ; Relocatable code ; ; Code entered with r0-r5=0, r6=top of memory br basic_startup ; Branch to start code halt ; some padding for future halt halt halt ; .startup_message EQUS "PDP11 BBC BASIC v0.10":EQUB 10:EQUB 13 EQUS "(C) Copyright J.G.Harston 1989":EQUB 10:EQUB 13 EQUB 0 align : .basic_startup ; should check if filename passed to CHAIN ; don't print startup message if CHAINing mov startup_message,r1 jsr pc,print_r1 ; bottom of memory is end of code+system variables ; top of memory is passed in r6 mov end_of_basic,r0 ; r0=bottom of memory mov sp,r1 ; r1=top of memory mov r0,SV_PAGE ; initialise bottom and mov r1,SV_MEMTOP ; and top of memory mov r1,sp ; put stack at top of memory ; ; .immediate_loop mov #ASC">",r0 jsr pc,IO_WRCH ; print ">" prompt mov CMD_BUF,r1 jsr pc,IO_READLINE ; Read a line of input ; ; tokenise it ; ; ; mov immediate_loop,pc ; jump back to command prompt BR immediate_loop takes ; 2 bytes less ; ; TOKEN TABLE EQUB &80:EQUS "AND" EQUB &81:EQUS "etc" : EQUB &FF:EQUS "OSCLI" EQUB &FF align halt : .print_r1 ; Print text pointed to by R1, term. by &00 mov r0,-(sp) ; push r0 .print_r1_loop movb (r1)+,r0 ; get byte from r1, inc r1 beq print_r1_end ; exit if final byte jsr pc,IO_WRCH br print_r1_loop ; loop back .print_r1_end mov (sp)+,r0 ; pop r0 rts pc ; and exit ; ; IO ROUTINES ; ; ***** GENERAL I/O ***** ; .IO_READLINE ; R1=>memory to read input string to ; In future, max/lochar/hichar mov r1,-(sp) ; Save pointer to buffer mov #0,r2 ; Zero number of characters read .IO_RDLNloop jsr pc,IO_RDCH ; Get a character bcs IO_RDLNesc ; Escape state cmp r0,#27;beq IO_RDLNesc ; Escape character (remove later) cmp r0,#13:beq IO_RDLNcr ; - End of line cmp r0,#10:beq IO_RDLNcr ; - End of line cmp r0,#21:beq IO_RDLNu ; Ctrl-U - delete line cmp r0,#127:beq IO_RDLNdel ; - del a character cmp r0,#8:beq IO_RDLNdel ; - del a character cmp r0,#ASC" ":bcs IO_RDLNloop; Ignore other control characters cmp r2,#240:bcc IO_RDLNloop ; No more room for characters movb r0,(r1)+ ; Put character into memory add r2,#1 ; Inc. number of characters jsr pc,IO_WRCH ; Output the character br IO_RDLNloop ; Go back for another ; .IO_RDLNu mov r2,r3 ; We want to delete all characters br IO_RDLNdelete .IO_RDLNdel mov #1,r3 ; We only want to delete one char .IO_RDLNdelete cmp r2,#0:beq IO_RDLNloop mov #127,r0 jsr pc,IO_WRCH ; Output character sub r1,r1,#1 ; Back address pointer sub r2,r2,#1 ; Dec character counter sub r3,r3,#1 ; Dec number to delete bne IO_RDLNdelete ; Delete more br IO_RDLNloop ; Go back into ReadLine loop ; .IO_RDLNesc jsr pc,IO_NEWL ; Print newline mov #0,r2 ; Length = 0 sec ; Set carry - escape bcs IO_RDLNend ; .IO_RDLNcr jsr pc,IO_NEWL ; Returns with r0= movb r0,(r1)+ ; Put terminator in clc ; Clear carry - ok .IO_RDLNend mov (sp)+,r1 ; Get buffer address back rts pc ; r0=, r1=buffer, r2=length ; ; ; ***** HOST I/O ***** ; .IO_QUIT emt 0 rts pc ; Won't actually get back! ; .IO_CLI emt 1 ; r1=>command string rts pc ; .IO_BYTE emt 2 ; Osbyte r0,r1,r2 rts pc ; .IO_WORD emt 3 ; Osword r0,r1=>block rts pc ; .IO_WRCH emt 4 ; Oswrch r0=char rts pc ; .IO_RDCH emt 5 ; Osrdch r0=char rts pc ; ; Filing entries, etc. ; ; ; System Variables ; Memory locations, increasing address .SV_MEMBOT equw &0000 ; Bottom of available memory .SV_PAGE equw &0000 ; PAGE - start of Basic program .SV_TOP equw &0000 ; End of Basic program .SV_LOMEM equw &0000 ; Start of Basic variable area .SV_VAREND equw &0000 ; End of Basic variable area .SV_STACK equw &0000 ; Bottom of Basic stack .SV_HIMEM equw &0000 ; Top of Basic stack/memory .SV_MEMTOP equw &0000 ; Top of available memory ; ; Interpreting pointers .SV_PTR equw &0000 ; Current byte being executed ; ; Buffers .STRING_BUF equm 256 ; String accumulator .CMD_BUF equm 256 ; Command Input buffer .tempstack ; Temporary startup stack in command buffer ; ; Default PAGE: .end_of_basic