From 8e03d81802a4ac49079d23c85938ce7e929c1ea7 Mon Sep 17 00:00:00 2001 From: "Tobias V. Langhoff" Date: Wed, 22 Apr 2020 22:15:34 +0200 Subject: [PATCH] Free 15 bytes by reorganizing code (1023 to 1008 bytes) * Load the last nibble of the CHIP-8 instruction (PIR+1) in the fetch routine * Move some branches to allow fallthrough --- CHIPOS68.asm | 75 +++++++++++++++++++++++++--------------------------- README.md | 2 +- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/CHIPOS68.asm b/CHIPOS68.asm index 45567b8..bcade9c 100755 --- a/CHIPOS68.asm +++ b/CHIPOS68.asm @@ -6,6 +6,7 @@ ; DREAM-6800 OPERATING SYSTEM WITH CHIP8 LANGUAGE INTERPRETER ; ; ORIGINATED BY MICHAEL J BAUER, DEAKIN UNIVERSITY, 1978 +; MODIFICATIONS BY TOBIAS V LANGHOFF, UNIVERSITY OF OSLO, 2020 ; ; www.mjbauer.biz/DREAM6800.htm ; @@ -81,34 +82,35 @@ FETCH: LDX PPC ; POINT TO NEXT INSTR STX PIR STX ZHI ; SAVE ADRS (MMM) JSR SKIP2 ; BUMP PRGM-CTR - LDAA ZHI ; MASK OFF ADRS - ANDA #$0F - STAA ZHI + LDAB ZHI ; MASK OFF ADRS + ANDB #$0F + STAB ZHI BSR FINDV ; EXTRACT VX ALSO - STAA VX ; STASH VX + STAB VX ; STASH VX STX VXLOC ; SAVE LOCATION OF VX - LDAA PIR+1 ; FIND Y - LSRA - LSRA - LSRA - LSRA + LDAB PIR+1 ; FIND Y + TBA ; STASH KK + LSRB + LSRB + LSRB + LSRB BSR FINDV ; EXTRACT VY - STAA VY ; STASH VY + STAB VY ; STASH VY EXEC: LDX #JUMTAB-2 ; POINT TO JUMP TABLE - LDAA PIR ; EXTRACT MSD - ANDA #$F0 + LDAB PIR ; EXTRACT MSD + ANDB #$F0 EXEl: INX ; FIND ROUTINE ADRS INX - SUBA #$10 + SUBB #$10 BCC EXEl ; BRANCH IF HIGHER OR SAME LDX 0,X ; LOAD ROUTINE ADRS JSR 0,X ; PERFORM ROUTINE BRA FETCH ; NEXT INSTR... FINDV: LDX #VO-1 ; POINT TO VARIABLES TABLE FIND1: INX ; FIND LOCN VX - DECA + DECB BPL FIND1 - LDAA 0,X ; FETCH VX FROM TABLE + LDAB 0,X ; FETCH VX FROM TABLE RTS ; ; JUMP TABLE(ROUTINE ADDRESSES) @@ -116,10 +118,10 @@ FIND1: INX ; FIND LOCN VX JUMTAB: FDB EXCALL ; ERASE, RET, CALL, NOP FDB GOTO ; GOTO MMM FDB DOSUB ; DO MMM - FDB SKFEK ; SKF VX=KK - FDB SKFNK ; SKF VX#KK + FDB SKFEQ ; SKF VX=KK + FDB SKFNE ; SKF VX#KK FDB SKFEV ; SKF VX=VY - FDB LETK ; Vx=KK + FDB PUTVX ; Vx=KK FDB LETVK ; VX=VX+KK FDB LETVV ; VX=[VX][+-&!]VY FDB SKFNV ; SKF VX#VY @@ -134,12 +136,12 @@ JUMTAB: FDB EXCALL ; ERASE, RET, CALL, NOP ; EXCALL: LDAB PIR ; GET INSTR REG BNE CALL - LDAA PIR+1 - CMPA #$E0 - BEQ ERASE CMPA #$EE BEQ RETDO - RTS ; NOP, FETCH + CMPA #$E0 + BNE RETMON ; NOP, FETCH + NOP ; PADDING FOR FALLTHROUGH + NOP ; PADDING FOR FALLTHROUGH ; ORG $C079 ; @@ -152,7 +154,7 @@ FILL: STAA 0,X ; FILL SCREEN WITH ACC-A INX CPX #ENDBUF ; DONE? BNE FILL - RTS +RETMON: RTS RETDO: TSX ; SAVE REAL SP LDS PSP PULA @@ -188,14 +190,9 @@ DOSUB: TSX ; SAVE SP ; ; CONDITIONAL SKIP ROUTINES ; -SKFEK: LDAA PIR+1 ; GET KK SKFEQ: CMPA VX BEQ SKIP2 RTS -SKFNK: LDAA PIR+1 ; GET KK -SKFNE: CMPA VX - BNE SKIP2 - RTS SKFEV: LDAA VY ; GET VY BRA SKFEQ SKFNV: LDAA VY @@ -212,23 +209,23 @@ SKFKEY: JSR KEYINP ; INTERROGATE KEYBOARD CMPB PIR+1 ; SKF VX#KEY BEQ SKIP2 RTS ; NO KEY GO FETCH -SKFK1: LDAB #$9E - CMPB PIR+1 ; WHAT INSTRN? +SKFK1: CMPA #$9E BEQ SKFEQ - BRA SKFNE +SKFNE: CMPA VX + BNE SKIP2 + RTS ; ; ARITHMETIC/LOGIC ROUTINES ; -LETK: LDAA PIR+1 ; GET KK - BRA PUTVX -LETVK: LDAA PIR+1 - ADDA VX +LETVK: ADDA VX BRA PUTVX RANDV: BSR RANDOM ; GET RANDOM BYTE ANDA PIR+1 BRA PUTVX -LETVV: LDAA VX - LDAB PIR+1 + +LETVV: TAB + LDAA VX + ANDB #$0F ; EXTRACT N BNE LETV1 LDAA VY ; VX=VY @@ -409,9 +406,9 @@ MOVX1: PULA ; GET NEXT V RTS ; ; DISPLAY ROUTINES -; -SHOW: LDAB PIR+1 ; GET N (OPCODE LSB) +SHOW: TAB ; GET N (OPCODE LSB) CLR VF ; CLEAR OVERLAP FLAG + NOP ; PADDING FOR FALLTHROUGH ; ORG $C224 ; diff --git a/README.md b/README.md index 609c22a..3dadbe5 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,4 @@ p2bin -l 0 CHIPOS68.p The CHIPOS code in this repo is also available for download on [Michael J. Bauer's DREAM 6800 website](http://www.mjbauer.biz/DREAM6800.htm). Michael has stated to me in private correspondence that the code is in the public domain. -This version contains several origins. These are not needed for assembly (besides the last one that makes sure the interrupt vectors are located at the highest addresses), but they also serve to denote sections of the code that programs will expect to stay put, should you wish to edit it while still staying CHIPOS-compatible. These addresses were all found in the document "CHIPOS SUBROUTINES (& Calling Sequences)" from Michael J. Bauer's website. +This version is a few (18) bytes smaller than the original CHIPOS, to make room for extra functionality. Therefore, it contains several origins to remain compatible with the addresses found in the document "CHIPOS SUBROUTINES (& Calling Sequences)" from Michael J. Bauer's website.