1 .define WRCH, RDCH, Earray, Erange, Eset
2 .define Eiovfl, Eidivz, Eiund, Econv
3 .define Estack, Eheap, Eillins, Eoddz
4 .define Ecase , Ebadmon, OSBYTE, MON
5 .define Ebadlin, Ebadgto, BASE, NBYTES
6 .define hol0, IGNMASK, ADDR, PROGNAME
7 .define LB, LBl, SP, HP, ERRPROC, UNSIGN
8 .define Ytmp, EXG, ARTH, RETURN, SIGN
9 .define RETSIZE, TRAPVAL, STACK, BRANCH
10 .define start, Push, Pop, STACKTh, STACKTl
22 ! The next three definitions are special for the
25 WRCH = 0x0FFEE ! This subroutine writes the character in
26 ! register A to the screen
27 RDCH = 0x0FFE0 ! This subroutine returns a character in
28 ! register A from the current input stream
29 OSBYTE = 0x0FFF4 ! This subroutine performs miscelaneous
30 ! operating system calls
32 F_DUM = 0 ! Dummy floating point constant
34 ! Here are the error numbers
53 BASE = 240 ! This is the offset from the localbase
54 ! for the second localbase
56 STACKTh = 0x78 ! This is the top of the stack
59 ! Some zeropage declarations
63 RES: .space 76 ! special for the operating system
65 hol0: .space 16 ! the hol0 block
67 IGNMASK: .space 2 ! can hold the ingnore mask
69 ADDR: .space 4 ! used for indirect addressing
71 LB: .space 2 ! the localbase
73 LBl: .space 2 ! the second localbase (localbase-BASE)
75 SP: .space 3 ! the stackpointer (real_stack)
77 HP: .space 2 ! the heap pointer
79 BRANCH: .space 2 ! used for branch instructions
81 ERRPROC: .space 2 ! can hold the address of the error handler
83 Ytmp: .space 1 ! used for intermediate storage in Y
85 EXG: .space 2 ! used by the exchange subroutine Exg
87 ARTH: .space 16 ! used for arithmetic
89 NBYTES: .space 2 ! containes the number of bytes for a block move
92 RETURN: .space 4 ! the return area
94 RETSIZE: .space 1 ! the size of the object returned
96 SIGN: .space 1 ! the sign of the calculation
98 UNSIGN : .space 1 ! is it signed or unsigned arithmetic
100 TRAPVAL: .space 1 ! intermediate storage of the error number
102 STACK: .space 1 ! contains the hardware stackpointer on
103 ! entering _m_a_i_n for a neat return
105 RESERVED: .space 112 ! used by the operating system
108 .base 0x0E02 ! where to start in the BBC micro
109 ! GENERAL PURPOSE ROUTINES
113 stx STACK ! save stackpointer for exit and error
115 ! The following three operating system calls are only
116 ! for the BBC microcomputer
121 jsr OSBYTE ! return control to the keyboard
125 jsr OSBYTE ! clear all internal buffers
129 jsr OSBYTE ! output to screen and RS423
132 sta LB ! set localbase (lowbyte)
135 sta SP ! set stackpointer (lowbyte)
136 sta ERRPROC ! set start address for error handler (lowbyte)
137 sta ERRPROC+1 ! set start address for error handler (highbyte)
138 sta hol0 ! set the line number (lowbyte)
139 sta hol0+1 ! set the line number (highbyte)
141 sta SP+1 ! set the stacpointer (highbyte)
142 sta LB+1 ! set the localbase (highbyte)
144 sta HP ! set the heap pointer (lowbyte)
146 sta HP+1 ! set the heap pointer (highbyte)
148 sta hol0+4 ! set fake programname pointer (lowbyte)
150 sta hol0+5 ! set fake programname pointer (highbyte)
152 sta ADDR ! start address of bss block (lowbyte)
154 sta ADDR+1 ! start address of bss block (highbyte)
157 4: ldx #[endbss].h ! clear bss block
159 bcc 1f ! end of bss block reached
163 bcc 1f ! end of bss block reached
171 jsr Push ! push fake envelope pointer
174 jsr Push ! push argv[0]
178 jsr __m_a_i_n ! start the real program
181 jsr WRCH ! send end of program to R423
184 jsr OSBYTE ! send output to screen only
187 jsr OSBYTE ! input only from R423
191 ldx STACK ! load stackpointer
194 txs ! reset hardware stackpointer
197 ! The subroutine Push pushes the registerpair AX onto the stack.
202 bne 1f ! lowbyte of stackpointer <> 0
203 dec SP+1 ! decrement highbyte of stackpointer
205 dey ! decrement lowbyte of stackpointer
206 sty SP+2 ! save lowbyte of stackpointer
209 sta (SP),y ! push X onto the stack
212 sta (SP),y ! push A onto the stack
217 ! The subroutine Pop pops the registerpair AX from the stack.
222 lda (SP),y ! pop X from the stack
225 lda (SP),y ! pop A from the stack
227 bne 1f ! lowbyte of stackpointer <> 0
228 inc SP+1 ! increment highbyte of stackpointer
229 1: sty SP+2 ! store lowbyte of stackpointer
237 PROGNAME: ! for initialising the programname pointer