From 1c5d216ea0242b36f28f4ee32c99c222761d422c Mon Sep 17 00:00:00 2001 From: ketmar Date: Tue, 12 Apr 2011 10:29:21 +0000 Subject: [PATCH] added XPrint8 module FossilOrigin-Name: c3fb675e80b4c4a3d7e464d81b15208e451e1f8f8d7e1d188ff0c9b8e19d7184 --- libs/XPrint8 | 373 +++++++++++++++++++++++++++++++++++++++++++++++ samples/xprint8/main.zas | 30 ++++ 2 files changed, 403 insertions(+) create mode 100644 libs/XPrint8 create mode 100644 samples/xprint8/main.zas diff --git a/libs/XPrint8 b/libs/XPrint8 new file mode 100644 index 0000000..89f0eb8 --- /dev/null +++ b/libs/XPrint8 @@ -0,0 +1,373 @@ + MODULE XPrint8 + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; print string; lat string byte must have bit 7 set +;; in: +;; HL: string address +;; out: +;; HL: next string address +;; AF: dead +PrintStrX: +.loop: + ld a,(hl) + and #7f + call PrintChar + ld a,(hl) + inc hl + and #80 + jr z,.loop + ret + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; print char +;; in: +;; A: char code +;; out: +;; AF: dead +PrintChar: +curProc: equ $+1 + jp printCharMain + +printOneMoreArg: + ld (curArg1),a + push hl + ld hl,printLastArg + ld (curProc),hl + pop hl + ret + +printLastArg: + push hl + ld (curArg0),a + ld hl,printCharMain + ld (curProc),hl + ld a,(curSpCode) + cp 22 + jr nz,.spcodeNotAt + ; at + ld hl,(curArgs) ; h:y; l:x + ld a,31 + cp l + jr nc,.spcodeAtXOk + ld l,a +.spcodeAtXOk: + ld a,23 + cp h + jr nc,.spcodeAtYOk + ld h,a +.spcodeAtYOk: + ld (curXY),hl +.pophlandquit: + pop hl + ret +.spcodeNotAt: + + cp 18 + jr nc,.spcodeNotInkPaper + ld h,a + ld a,(curArg0) + cp 8 + jr nc,.pophlandquit + push de + ld e,%11111000 + bit 0,h ; 17? + jr z,.notPaper + ; paper: *8 + ld e,%11000111 + rlca + rlca + rlca +.notPaper: + ld d,a + ld hl,curAttr + ld a,(hl) + and e + or d + ld (hl),a + pop de,hl + ret +.spcodeNotInkPaper: + + ld hl,curAttr + + cp 19 + jr nz,.spcodeNotBright + res 6,(hl) + ld a,(curArg0) + or a + jr z,.pophlandquit + set 6,(hl) + pop hl + ret +.spcodeNotBright: + + cp 18 + jr nz,.spcodeNotFlash + res 7,(hl) + ld a,(curArg0) + or a + jr z,.pophlandquit + set 7,(hl) + pop hl + ret +.spcodeNotFlash: + + cp 20 + jr nz,.spcodeNotInverse + ld a,(curArg0) + or a + jr z,.invNormal + ld a,$2F ; CPL +.invNormal: + ld (PrintCharAtHLInvMode),a + pop hl + ret + +.spcodeNotInverse: + cp 21 + jr nz,.spcodeNotOver + ld a,(curArg0) + or a + jr z,.overNormal + dec a + ld a,$AE ; XOR (HL) + jr z,.overNormal + ld a,$B6 ; OR (HL) +.overNormal: + ld (PrintCharAtHLOverMode),a + pop hl + ret + +.spcodeNotOver: + cp 23 + jr nz,.pophlandquit + ld l,31 + ld a,(curArg0) + cp a + jr nc,.spcodeXXOK + ld a,l +.spcodeXXOK: + ld (curX),a + pop hl + ret + + +;; special codes: +;; 6: tab (n/a) +;; 7: ??? (n/a) +;; 8: bs +;; 9: right +;; 10: curdown (same as 13 for now) +;; 11: curup (n/a) +;; 12: del (n/a) +;; 13: enter (x=0;++y) +;; 14: n/a +;; 15: n/a +;; 16: ink +;; 17: paper +;; 18: flash +;; 19: bright +;; 20: inverse +;; 21: over +;; 22: at +;; 23: tab ctl (n/a); for now: move to the given x + +printCharMain: + cp 32 + jr nc,.printable + cp 16 + jr c,.notCtl + cp 24 + jr nc,.notCtl + ; special + push hl + ld (curSpCode),a + cp 22 ; at + ld hl,printOneMoreArg + jr z,.itsAt + ; one byte + IF printOneMoreArg/256 = printLastArg/256 + ld l,printLastArg%256 + ELSE + ld hl,printLastArg + ENDIF +.itsAt: +.quitSetProcHL: + ld (curProc),hl + pop hl + ret + +.notCtl: + cp 10 ; lf + jr z,.printLF + cp 13 ; cr + jr z,.printCR + cp 8 ; bs + jr z,.printBS + cp 9 ; right + jr nz,.printable + push hl + jr .printRightX + +.printable: + cp 128 + ret nc + + ; normal print + push hl,de,af + ld de,(curXY) + call scrAddr8DE_HL + pop af + call PrintCharAtHL + call scr2attrHL + pop de + ld a,(curAttr) + ld (hl),a + +.printRightX: + ld hl,(curXY) + inc l + ld a,31 + cp l + jr nc,.pokNC + ld l,0 + inc h + ld a,23 + cp h + jr nc,.pokNC + ld h,l +.pokNC: + ld (curXY),hl + pop hl + ret + +.printBS: + ld a,(curX) + sub a,1 + jr nc,.putAtoXandRet + ld a,(curY) + sub a,1 + ret c + ld (curY),a + ld a,31 + jr .putAtoXandRet + +.printLF: + push hl + ld hl,curXY+1 + inc (hl) + pop hl + +.printCR: + xor a +.putAtoXandRet: + ld (curX),a + ret + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; print char to screen +;; in: +;; HL: screen address +;; A: char code +PrintCharAtHL: + push bc,hl + ld l,a + cp 52 + jr z,.distortNot + cp 96 + ld a,7 + jr c,.distortOk +.distortNot: + ld a,#ff +.distortOk: + ld (.andOper),a + ld h,0 + add hl,hl + add hl,hl + add hl,hl + ld de,#3c00 + add hl,de + pop de + push de + ex de,hl + ld b,8 +.lineloop: + ld a,(de) + ld c,a + and #7C + rlca + or c + ; distort a little + ld c,a + ld a,b + cp 3 + ld a,c + jr nz,.dontfuck +.andOper: equ $+1 + and #07 +.dontfuck: + ; +@PrintCharAtHLInvMode: + nop ; or CPL ($2F) + ; for OVER +@PrintCharAtHLOverMode: + or a ; or a($AF) / xor (hl)($AE) / or (hl)($B6) + ; end OVER + ld (hl),a + inc de + inc h + djnz .lineloop + ; + pop hl,bc + ret + + +; in: +; D: y (char) +; E: x (char) +; out: +; HL: scrAddr +; AF: dead +scrAddr8DE_HL: + ld a,d + and #18 + or #40 + ld h,a + ld a,d + rrca + rrca + rrca + and #E0 + or e + ld l,a + ret + + +; in: +; HL: scrAddr +; out: +; HL: attrAddr +scr2attrHL: + ld a,h + rrca + rrca + rrca + and #03 + or #58 + ld h,a + ret + +curSpCode: db 0 +curArgs: equ $ +curArg0: db 0 +curArg1: db 0 + +curAttr: db 007 +curXY: equ $ +curX: db 0 +curY: db 0 + + ENDMODULE diff --git a/samples/xprint8/main.zas b/samples/xprint8/main.zas new file mode 100644 index 0000000..68874d6 --- /dev/null +++ b/samples/xprint8/main.zas @@ -0,0 +1,30 @@ +; ***************************************************************************** +; * Special FX Music Player Engine +; * +; * Based on code written by Jonathan Smith for the Special FX game, Firefly. +; * Modified by Chris Cowley +; * +; * modified by Ketmar // Vampire Avalon +; ****************************************************************************** + ORG 32768 + ENT 32768 + CLR 32767 + +MainEntry: + ld hl,xmsg + call XPrint8.PrintStrX +.xloop: + ld a,31 + inc a + cp 128 + jr z,.done + ld (.xloop+1),a + call XPrint8.PrintChar + jr .xloop +.done: + ret + +xmsg + dx "\22\9\10\19\1 HELLO FOLKS \19\0\16\5\17\1\22\0\0printer\n\9test\18\1!\18\0\n$$$\8\8\8\21\1" + + INCLUDE -- 2.11.4.GIT