Programming samples by Robert Elton Maas Handcoded machine language (MOS 6502) These are excerpts from the file DM2SIM.ASM (36k bytes total): MOS 6502 owned by REM DM2SIM (Datamedia, or other smart terminal, emulator with line-map) Interrupt handler (suitable for any 7-bit TTY-mode), assembly-code ;Temporarily use location 3 non-reentrantly to allow use of register A ; to fetch old processor status which contains BRK flag... label opcode address or data <- octal -< abs.adr BRKCHK: STAZ SAVA=3 003 205 \1023 PLA ;Fetch saved-psw to discover 150 PHA ; cause of interrupt... 110 ANDI BBIT=20 ;was int. due to BRK? 020 051 BEQ .+3 003 360 JMP BRKIN=176070 ;yes, PROM ODT 374 070 114 \1033 LDAZ SAVA=3 ;no, IRQ due to UART... 003 245 \1036 ;Same state as above (register A restored there, stack restored above) ;During handling of interrupt, old psw automatically saved on stack above, ; registers saved on stack here... GOTIRQ: PHA 110 \1040 TXA 212 PHA 110 TYA 230 PHA 110 ;Main loop looking for cause of interrupt. ;After finding a cause, restart search at top again to catch ; other pending interrupt-causes before returning from interrupt... L1: LDA MODC=174120 370 120 255 \1045 LSRA ;leftmost bit easiest to test 112 BCC L2 ;test modem-input data-ready 025 220 ;Interrupt caused by character ready from modem... LDAZ CO-INTMI-HI=365 365 245 \1053 PHA 110 LDAZ CO-INTMI-LO=364 364 245 PHA 110 LDA MODD=174121 370 121 255 ANDI 177 177 051 RTS ;[continue process MI] 140 INTMIZ: PLA 150 \1067 STAZ CO-INTMI-LO=364 364 205 PLA 150 STAZ CO-INTMI-HI=365 365 205 JMP L1=1045 002 045 114 L2: LSRA now this bit leftmost 112 \1100 BCC L3=1115 014 220 LDAZ MODCTL=370 370 245 \1103 ANDI XMTIRQ=040 040 051 BEQ L3=1115 006 360 ;Interrupt caused by transmit-to-modem done... JSR INTMO=4211(#) ;[process MO] 010 211 040 \1111 JMP L1=1045 002 045 114 L3: LDA BEEC=174100 370 100 255 \1117 LSRA ;leftmost bit again 112 BCC L4=1131 013 220 ;Interrupt caused by character typed on terminal... LDA BEED=174101 370 101 255 \1125 ANDI 177 177 051 JSR INTBI=4153(#) [process BI] 010 153 040 \1132 JMP L1=1045 002 045 114 L4: LSRA ;now this bit leftmost again 112 \1140 BCC L5 012 220 LDAZ BOBUSY=372 372 245 \1143 BNE L5 006 320 LDAZ BEECTL=371 371 245 \1147 ANDI XMTIRQ=040 040 051 BNE L6 006 320 ;If it falls thru to here, none of the above four causes of ; interrupt are pending currently. We assume there is no other ; possible cause of interrupt so we restore registers and return... L5: PLA 150 \1155 TAY 250 PLA 150 TAX 252 PLA 150 ;Registers restored, psw and pc will be restored by RTI... RTI ;return from interrupt 100 ;No bells pending, normal contination of process BO. ;Since this process eats up lots of CPU time, to avoid missing ; incoming characters this process runs with interrupts enabled. ;To avoid entering itself recursively, interrupts caused by ; output-to-terminal done are specially disabled... L7: LDAI XMTIRQ=040 040 251 \1201 STAZ BOBUSY=372 372 205 LDAI (not XMTIRQ)=337 337 251 ANDZ BEECTL=371 371 045 STA BEEC=174100 370 100 215 CLI ;arm CPU interrupts! 130 \1214 LDAZ CO-INTBO-HI=367 367 245 \1215 PHA 110 LDAZ CO-INTBO-LO=366 366 245 PHA 110 RTS ;[continue process BO] 140 ;If process BO has loaded into register A a character to transmit... INTBOZ: STA BEED=174101 370 101 215 \1224 ;If process BO thinks it is done, return here instead... INTBZZ: PLA 150 \1227 STAZ CO-INTBO-LO=366 366 205 PLA 150 STAZ CO-INTBO-HI=367 367 205 SEI ;disarm CPU interrupts again 170 \1235 ;Clear BOBUSY to 0 and set BEEC to equal BEECTL now so that ; if process BO is active then BO-interrupts will be re-enabled... LDAI 0 000 251 \1236 STAZ BOBUSY=372 372 205 LDAZ BEECTL=371 371 245 STA BEEC=174100 370 100 215 JMP L1=1045 002 045 114 \1247 (next free location) \1252 DM2SIM -- INTMO (Modem-Output interrupt handler) ;Syntax (by INTBI) will be repeated here: ; In normal mode, any character escept CTRL-SHIFT-L will be passed ; as a single-character token. CTRL-SHIFT-L will enter escape mode. ; In escape mode, all characters whatsoever (including ctrl-shift-L ; itself) are passed as two-character sequences LEECH CHAR. ;Semantics are given here: ; LEECH specialchar --> do special function (see table later) ; LEECH char --> transmit char XOR '100 (i.e. controlify or ; uncontrolify the character) ; char --> transmit char as-is label opcode address or data <- octal -< rel.adr ABS INTMO: LDAZ MOBUF=363 363 245 \ 00 4211 BPL INTMO1 012 020 LDAZ MODCTL=370 370 245 \ 04 ANDI (not XMTIRQ)=337 337 051 STAZ MODCTL=370 370 205 STA MODC=174120 370 120 215 RTS 140 INTMO1: LDXZ MOESC=360 360 246 \ 16 BMI INTMO2 ;Normal char, keep as-is 021 060 CPXI ^\=034 034 340 \ 22 BEQ .+2 002 360 BRK 0 ;BUG IN EMULATOR 000 000 CMPI ^C=003 ;ctrl-\ ctrl-C 003 311 \ 30 BNE INTMO3 ;Go try other special codes 021 320 BRK 0 ;Octal DDT 000 000 \ 34 JMP 1020 ; then restart emulator 002 020 114 BOCTRL: EORI CTRL=100 100 111 \ 41 INTMO2: STA MODD=174121 370 121 215 \ 43 BODONE: LDAI EMPTY=200 200 251 \ 46 STAZ MOBUF=363 363 205 STAZ MOESC=360 360 205 RTS 140