Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#277 from boriel/bugfix/scroll
Browse files Browse the repository at this point in the history
Bugfix/scroll
  • Loading branch information
boriel committed May 10, 2020
2 parents 30a5e71 + 313c978 commit 3593074
Show file tree
Hide file tree
Showing 58 changed files with 1,999 additions and 2,502 deletions.
68 changes: 43 additions & 25 deletions library-asm/print.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; vim:ts=4:sw=4:et:
; vim:ts=4:sw=4:et:
; PRINT command routine
; Does not print attribute. Use PRINT_STR or PRINT_NUM for that

Expand Down Expand Up @@ -50,7 +51,6 @@ __PRINTCHAR: ; Print character store in accumulator (A register)
LOCAL __PRINT_UDG
LOCAL __PRGRAPH
LOCAL __PRINT_START
LOCAL __NO_SCROLL
LOCAL __ROM_SCROLL_SCR
LOCAL __TVFLAGS

Expand All @@ -62,32 +62,40 @@ PRINT_JUMP_STATE EQU __PRINT_JUMP + 1
__PRINT_JUMP:
jp __PRINT_START ; Where to jump. If we print 22 (AT), next two calls jumps to AT1 and AT2 respectively

#ifndef DISABLE_SCROLL
LOCAL __SCROLL
__SCROLL: ; Scroll?
ld hl, __TVFLAGS
bit 1, (hl)
ret z
call __ROM_SCROLL_SCR
ld hl, __TVFLAGS
res 1, (hl)
ret
#endif

__PRINT_START:
cp ' '
jp c, __PRINT_SPECIAL ; Characters below ' ' are special ones

exx ; Switch to alternative registers
ex af, af' ; Saves a value (char to print) for later

ld hl, __TVFLAGS
bit 1, (hl)
jp z, __NO_SCROLL
call __ROM_SCROLL_SCR
ld hl, __TVFLAGS
res 1, (hl)
__NO_SCROLL:
#ifndef DISABLE_SCROLL
call __SCROLL
#endif
call __LOAD_S_POSN

; At this point we have the new coord
ld hl, (SCREEN_ADDR)

ld a, d
ld c, a ; Saves it for later
ld c, a ; Saves it for later
and 0F8h ; Masks 3 lower bit ; zy
ld d, a

ld a, c ; Recovers it
ld a, c ; Recovers it
and 07h ; MOD 7 ; y1
rrca
rrca
Expand Down Expand Up @@ -125,9 +133,9 @@ __SRCADDR:
ld bc, (CHARS)

__PRGRAPH0:
add a, a ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
add a, a ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
ld l, a
ld h, 0 ; HL = a * 2 (accumulator)
ld h, 0 ; HL = a * 2 (accumulator)
add hl, hl
add hl, hl ; HL = a * 8
add hl, bc ; HL = CHARS address
Expand All @@ -142,20 +150,20 @@ __PRGRAPH:
__PRCHAR:
ld a, (de) ; DE *must* be ALWAYS source, and HL destiny

PRINT_MODE: ; Which operation is used to write on the screen
PRINT_MODE: ; Which operation is used to write on the screen
; Set it with:
; LD A, <OPERATION>
; LD (PRINT_MODE), A
;
; Available opertions:
; NORMAL: 0h --> NOP ; OVER 0
; XOR : AEh --> XOR (HL) ; OVER 1
; OR : B6h --> OR (HL) ; PUTSPRITE
; AND : A6h --> AND (HL) ; PUTMASK
nop ;
; NORMAL : 0h --> NOP ; OVER 0
; XOR : AEh --> XOR (HL) ; OVER 1
; OR : B6h --> OR (HL) ; PUTSPRITE
; AND : A6h --> AND (HL) ; PUTMASK
nop ;

INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
nop ; 2F -> CPL -> INVERSE 1
INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
nop ; 2F -> CPL -> INVERSE 1

ld (hl), a

Expand Down Expand Up @@ -196,6 +204,9 @@ PRINT_EOL: ; Called WHENEVER there is no ";" at end of PRINT sentence
exx

__PRINT_0Dh: ; Called WHEN printing CHR$(13)
#ifndef DISABLE_SCROLL
call __SCROLL
#endif
call __LOAD_S_POSN

__PRINT_EOL1: ; Another entry called from PRINT when next line required
Expand All @@ -209,9 +220,13 @@ __PRINT_AT1_END:
ld hl, (MAXY)
cp l
jr c, __PRINT_EOL_END ; Carry if (MAXY) < d
#ifndef DISABLE_SCROLL
ld hl, __TVFLAGS
set 1, (hl)
ld a, d
#else
xor a
#endif

__PRINT_EOL_END:
ld d, a
Expand Down Expand Up @@ -449,7 +464,7 @@ LOOP:
ret
ENDP

PRINT_AT: ; CHanges cursor to ROW, COL
PRINT_AT: ; Changes cursor to ROW, COL
; COL in A register
; ROW in stack

Expand All @@ -460,7 +475,10 @@ PRINT_AT: ; CHanges cursor to ROW, COL

call __IN_SCREEN
ret nc ; Return if out of screen

#ifndef DISABLE_SCROLL
ld hl, __TVFLAGS
res 1, (hl)
#endif
jp __SAVE_S_POSN

LOCAL __PRINT_COM
Expand Down Expand Up @@ -498,16 +516,16 @@ __PRINT_TABLE: ; Jump table for 0 .. 22 codes
DW __PRINT_NOP ; 11
DW __PRINT_NOP ; 12
DW __PRINT_0Dh ; 13
DW __PRINT_BOLD ; 14
DW __PRINT_BOLD ; 14
DW __PRINT_ITA ; 15
DW __PRINT_INK ; 16
DW __PRINT_PAP ; 17
DW __PRINT_FLA ; 18
DW __PRINT_BRI ; 19
DW __PRINT_INV ; 20
DW __PRINT_OVR ; 21
DW __PRINT_AT ; 22 AT
DW __PRINT_TAB ; 23 TAB
DW __PRINT_AT ; 22 AT
DW __PRINT_TAB ; 23 TAB

ENDP
Expand Down
56 changes: 32 additions & 24 deletions tests/functional/astore16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -730,34 +730,38 @@ __PRINTCHAR: ; Print character store in accumulator (A register)
LOCAL __PRINT_UDG
LOCAL __PRGRAPH
LOCAL __PRINT_START
LOCAL __NO_SCROLL
LOCAL __ROM_SCROLL_SCR
LOCAL __TVFLAGS
__ROM_SCROLL_SCR EQU 0DFEh
__TVFLAGS EQU 5C3Ch
PRINT_JUMP_STATE EQU __PRINT_JUMP + 1
__PRINT_JUMP:
jp __PRINT_START ; Where to jump. If we print 22 (AT), next two calls jumps to AT1 and AT2 respectively
__PRINT_START:
cp ' '
jp c, __PRINT_SPECIAL ; Characters below ' ' are special ones
exx ; Switch to alternative registers
ex af, af' ; Saves a value (char to print) for later
LOCAL __SCROLL
__SCROLL: ; Scroll?
ld hl, __TVFLAGS
bit 1, (hl)
jp z, __NO_SCROLL
ret z
call __ROM_SCROLL_SCR
ld hl, __TVFLAGS
res 1, (hl)
__NO_SCROLL:
ret
#line 75 "/zxbasic/library-asm/print.asm"
__PRINT_START:
cp ' '
jp c, __PRINT_SPECIAL ; Characters below ' ' are special ones
exx ; Switch to alternative registers
ex af, af' ; Saves a value (char to print) for later
call __SCROLL
#line 86 "/zxbasic/library-asm/print.asm"
call __LOAD_S_POSN
; At this point we have the new coord
ld hl, (SCREEN_ADDR)
ld a, d
ld c, a ; Saves it for later
ld c, a ; Saves it for later
and 0F8h ; Masks 3 lower bit ; zy
ld d, a
ld a, c ; Recovers it
ld a, c ; Recovers it
and 07h ; MOD 7 ; y1
rrca
rrca
Expand Down Expand Up @@ -785,9 +789,9 @@ __PRINT_UDG:
__SRCADDR:
ld bc, (CHARS)
__PRGRAPH0:
add a, a ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
add a, a ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
ld l, a
ld h, 0 ; HL = a * 2 (accumulator)
ld h, 0 ; HL = a * 2 (accumulator)
add hl, hl
add hl, hl ; HL = a * 8
add hl, bc ; HL = CHARS address
Expand All @@ -800,19 +804,19 @@ __PRGRAPH:
ld b, 8 ; 8 bytes per char
__PRCHAR:
ld a, (de) ; DE *must* be ALWAYS source, and HL destiny
PRINT_MODE: ; Which operation is used to write on the screen
PRINT_MODE: ; Which operation is used to write on the screen
; Set it with:
; LD A, <OPERATION>
; LD (PRINT_MODE), A
;
; Available opertions:
; NORMAL: 0h --> NOP ; OVER 0
; XOR : AEh --> XOR (HL) ; OVER 1
; OR : B6h --> OR (HL) ; PUTSPRITE
; AND : A6h --> AND (HL) ; PUTMASK
nop ;
INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
nop ; 2F -> CPL -> INVERSE 1
; NORMAL : 0h --> NOP ; OVER 0
; XOR : AEh --> XOR (HL) ; OVER 1
; OR : B6h --> OR (HL) ; PUTSPRITE
; AND : A6h --> AND (HL) ; PUTMASK
nop ;
INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
nop ; 2F -> CPL -> INVERSE 1
ld (hl), a
inc de
inc h ; Next line
Expand Down Expand Up @@ -843,6 +847,8 @@ __PRINT_SPECIAL: ; Jumps here if it is a special char
PRINT_EOL: ; Called WHENEVER there is no ";" at end of PRINT sentence
exx
__PRINT_0Dh: ; Called WHEN printing CHR$(13)
call __SCROLL
#line 209 "/zxbasic/library-asm/print.asm"
call __LOAD_S_POSN
__PRINT_EOL1: ; Another entry called from PRINT when next line required
ld e, 0
Expand Down Expand Up @@ -1057,7 +1063,7 @@ LOOP:
djnz LOOP
ret
ENDP
PRINT_AT: ; CHanges cursor to ROW, COL
PRINT_AT: ; Changes cursor to ROW, COL
; COL in A register
; ROW in stack
pop hl ; Ret address
Expand All @@ -1066,6 +1072,8 @@ PRINT_AT: ; CHanges cursor to ROW, COL
ex de, hl
call __IN_SCREEN
ret nc ; Return if out of screen
ld hl, __TVFLAGS
res 1, (hl)
jp __SAVE_S_POSN
LOCAL __PRINT_COM
LOCAL __BOLD
Expand Down Expand Up @@ -1100,16 +1108,16 @@ __PRINT_TABLE: ; Jump table for 0 .. 22 codes
DW __PRINT_NOP ; 11
DW __PRINT_NOP ; 12
DW __PRINT_0Dh ; 13
DW __PRINT_BOLD ; 14
DW __PRINT_BOLD ; 14
DW __PRINT_ITA ; 15
DW __PRINT_INK ; 16
DW __PRINT_PAP ; 17
DW __PRINT_FLA ; 18
DW __PRINT_BRI ; 19
DW __PRINT_INV ; 20
DW __PRINT_OVR ; 21
DW __PRINT_AT ; 22 AT
DW __PRINT_TAB ; 23 TAB
DW __PRINT_AT ; 22 AT
DW __PRINT_TAB ; 23 TAB
ENDP
#line 53 "astore16.bas"
#line 1 "printu16.asm"
Expand Down

0 comments on commit 3593074

Please sign in to comment.