Merge branch 'cc65:master' into master

This commit is contained in:
rumbledethumps
2025-05-24 21:39:17 -07:00
committed by GitHub
42 changed files with 2801 additions and 147 deletions

35
libsrc/atari/cpeekc.s Normal file
View File

@@ -0,0 +1,35 @@
;
; 2016-02-28, Groepaz
; 2017-06-21, Greg King
;
; char cpeekc (void);
;
.export _cpeekc
.include "atari.inc"
_cpeekc:
lda OLDCHR ; get char under cursor
and #<~$80 ; remove reverse bit
;; convert internal screen code to AtSCII
tay
and #%01100000
asl a
asl a
rol a
rol a
tax
tya
eor intats,x
ldx #>$0000
rts
.rodata
intats: .byte %00100000 ; -> %001xxxxx
.byte %01100000 ; -> %010xxxxx
.byte %01000000 ; -> %000xxxxx
.byte %00000000 ; -> %011xxxxx

View File

@@ -0,0 +1,8 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

View File

@@ -0,0 +1,18 @@
;
; 2017-06-21, Greg King
;
; unsigned char cpeekrevers (void);
;
.export _cpeekrevers
.include "atari.inc"
_cpeekrevers:
lda OLDCHR ; get char under cursor
and #$80 ; get reverse bit
asl a
tax ; ldx #>$0000
rol a ; return boolean value
rts

21
libsrc/atmos/cpeekc.s Normal file
View File

@@ -0,0 +1,21 @@
;
; 2016-02-28, Groepaz
; 2017-06-19, Greg King
;
; char cpeekc (void);
;
; Atmos version
;
.export _cpeekc
.import setscrptr
.importzp ptr2
_cpeekc:
jsr setscrptr ; Set ptr2 and .Y to the cursor's address
lda (ptr2),y ; Get char
and #<~$80 ; Remove revers() bit
ldx #>$0000
rts

10
libsrc/atmos/cpeekcolor.s Normal file
View File

@@ -0,0 +1,10 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
; Atmos version
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

View File

@@ -0,0 +1,22 @@
;
; 2017-06-08, Greg King
;
; unsigned char cpeekrevers (void);
;
; Atmos version
;
.export _cpeekrevers
.import setscrptr
.importzp ptr2
_cpeekrevers:
jsr setscrptr ; Set ptr2 and .Y to the cursor's address
lda (ptr2),y ; Get char
and #$80 ; get reverse bit
asl a
tax ; ldx #>$0000
rol a ; return boolean value
rts

54
libsrc/atmos/cpeeks.s Normal file
View File

@@ -0,0 +1,54 @@
;
; 2017-06-20, Greg King
;
; void cpeeks (char* s, unsigned length);
;
.export _cpeeks
.import setscrptr, popax
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.macpack generic
_cpeeks:
eor #<$FFFF ; counting a word upward is faster
sta ptr3 ; so, we use -(length + 1)
txa
eor #>$FFFF
sta ptr3+1
jsr setscrptr ; Set ptr2 and .Y to the cursor's address
sty tmp2
jsr popax
sta tmp1 ; (will be a .Y index)
stx ptr1+1
ldx #<$0000
stx ptr1
bze L3 ; branch always
L4: ldy tmp2
lda (ptr2),y ; Get char
iny
bnz L2
inc ptr2+1
L2: sty tmp2
and #<~$80 ; Remove reverse bit
ldy tmp1
sta (ptr1),y
iny
bnz L1
inc ptr1+1
L1: sty tmp1
L3: inc ptr3 ; count length
bnz L4
inc ptr3+1
bnz L4
txa ; terminate the string
ldy tmp1
sta (ptr1),y
rts

View File

@@ -90,22 +90,7 @@ read_loop:
bne :+
inc ptr4+1
; The next code line:
;
; .byte $c9, "\n"
;
; corresponds to a CMP #imm with the target-specific newline value as its operand.
; This works because (with the 'string_escapes' feature enabled), the "\n" string
; assembles to the target-specific value for the newline character.
;
; It would be better if we could just write:
;
; cmp #'\n'
;
; Unfortunately, ca65 doesn't currently handle escape characters in character
; constants. In the longer term, fixing that would be the preferred solution.
: .byte $c9, "\n" ; cmp #'\n'
: cmp #'\n' ; #'\n' should get translated properly
beq done
bne read_loop

207
libsrc/common/lzsa1.s Normal file
View File

@@ -0,0 +1,207 @@
; void __fastcall__ decompress_lzsa1(const void *src, void *dest)
;
; NMOS 6502 decompressor for data stored in Emmanuel Marty's LZSA1 format.
;
; Compress with:
; lzsa -r -f 1 input.bin output.lzsa1
;
; Copyright John Brandwood 2021.
;
; Distributed under the Boost Software License, Version 1.0.
; Boost Software License - Version 1.0 - August 17th, 2003
;
; Permission is hereby granted, free of charge, to any person or organization
; obtaining a copy of the software and accompanying documentation covered by
; this license (the "Software") to use, reproduce, display, distribute,
; execute, and transmit the Software, and to prepare derivative works of the
; Software, and to permit third-parties to whom the Software is furnished to
; do so, all subject to the following:
;
; The copyright notices in the Software and this entire statement, including
; the above license grant, this restriction and the following disclaimer,
; must be included in all copies of the Software, in whole or in part, and
; all derivative works of the Software, unless such copies or derivative
; works are solely in the form of machine-executable object code generated by
; a source language processor.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
; SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
; FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
.export _decompress_lzsa1
.import popax
.importzp ptr1, ptr2, ptr3, ptr4, tmp1, tmp2, tmp3
lzsa_cmdbuf = tmp1 ; 1 byte.
lzsa_winptr = ptr1 ; 1 word.
lzsa_srcptr = ptr2 ; 1 word.
lzsa_dstptr = ptr3 ; 1 word.
lzsa_offset = lzsa_winptr
.proc _decompress_lzsa1
sta lzsa_dstptr
stx lzsa_dstptr+1
jsr popax
sta lzsa_srcptr
stx lzsa_srcptr+1
lzsa1_unpack: ldy #0 ; Initialize source index.
ldx #0 ; Initialize hi-byte of length.
;
; Copy bytes from compressed source data.
;
; N.B. X=0 is expected and guaranteed when we get here.
;
cp_length: lda (lzsa_srcptr),y
inc lzsa_srcptr
bne cp_skip0
inc lzsa_srcptr+1
cp_skip0: sta lzsa_cmdbuf ; Preserve this for later.
and #$70 ; Extract literal length.
lsr ; Set CC before ...
beq lz_offset ; Skip directly to match?
lsr ; Get 3-bit literal length.
lsr
lsr
cmp #$07 ; Extended length?
bcc cp_got_len
jsr get_length ; X=0, CS from CMP, returns CC.
stx cp_npages+1 ; Hi-byte of length.
cp_got_len: tax ; Lo-byte of length.
cp_byte: lda (lzsa_srcptr),y ; CC throughout the execution of
sta (lzsa_dstptr),y ; of this .cp_page loop.
inc lzsa_srcptr
bne cp_skip1
inc lzsa_srcptr+1
cp_skip1: inc lzsa_dstptr
bne cp_skip2
inc lzsa_dstptr+1
cp_skip2: dex
bne cp_byte
cp_npages: lda #0 ; Any full pages left to copy?
beq lz_offset
dec cp_npages+1 ; Unlikely, so can be slow.
bcc cp_byte ; Always true!
;
; Copy bytes from decompressed window.
;
; Longer but faster.
;
; N.B. X=0 is expected and guaranteed when we get here.
;
lz_offset: lda (lzsa_srcptr),y ; Get offset-lo.
inc lzsa_srcptr
bne offset_lo
inc lzsa_srcptr+1
offset_lo: sta lzsa_offset
lda #$FF ; Get offset-hi.
bit lzsa_cmdbuf
bpl offset_hi
lda (lzsa_srcptr),y
inc lzsa_srcptr
bne offset_hi
inc lzsa_srcptr+1
offset_hi: sta lzsa_offset+1
lz_length: lda lzsa_cmdbuf ; X=0 from previous loop.
and #$0F
adc #$03 ; Always CC from .cp_page loop.
cmp #$12 ; Extended length?
bcc got_lz_len
jsr get_length ; X=0, CS from CMP, returns CC.
got_lz_len: inx ; Hi-byte of length+256.
eor #$FF ; Negate the lo-byte of length
tay
eor #$FF
get_lz_dst: adc lzsa_dstptr ; Calc address of partial page.
sta lzsa_dstptr ; Always CC from previous CMP.
iny
bcs get_lz_win
beq get_lz_win ; Is lo-byte of length zero?
dec lzsa_dstptr+1
get_lz_win: clc ; Calc address of match.
adc lzsa_offset ; N.B. Offset is negative!
sta lzsa_winptr
lda lzsa_dstptr+1
adc lzsa_offset+1
sta lzsa_winptr+1
lz_byte: lda (lzsa_winptr),y
sta (lzsa_dstptr),y
iny
bne lz_byte
inc lzsa_dstptr+1
dex ; Any full pages left to copy?
bne lz_more
jmp cp_length ; Loop around to the beginning.
lz_more: inc lzsa_winptr+1 ; Unlikely, so can be slow.
bne lz_byte ; Always true!
;
; Get 16-bit length in X:A register pair, return with CC.
;
; N.B. X=0 is expected and guaranteed when we get here.
;
get_length: clc ; Add on the next byte to get
adc (lzsa_srcptr),y ; the length.
inc lzsa_srcptr
bne skip_inc
inc lzsa_srcptr+1
skip_inc: bcc got_length ; No overflow means done.
clc ; MUST return CC!
tax ; Preserve overflow value.
extra_byte: jsr get_byte ; So rare, this can be slow!
pha
txa ; Overflow to 256 or 257?
beq extra_word
check_length: pla ; Length-lo.
bne got_length ; Check for zero.
dex ; Do one less page loop if so.
got_length: rts
extra_word: jsr get_byte ; So rare, this can be slow!
tax
bne check_length ; Length-hi == 0 at EOF.
finished: pla ; Length-lo.
pla ; Decompression completed, pop
pla ; return address.
rts
get_byte: lda (lzsa_srcptr),y ; Subroutine version for when
inc lzsa_srcptr ; inlining isn't advantageous.
bne got_byte
inc lzsa_srcptr+1 ; Inc & test for bank overflow.
got_byte: rts
.endproc

308
libsrc/common/lzsa2.s Normal file
View File

@@ -0,0 +1,308 @@
; void __fastcall__ decompress_lzsa2(const void *src, void *dest)
;
; NMOS 6502 decompressor for data stored in Emmanuel Marty's LZSA2 format.
;
; Compress with:
; lzsa -r -f 2 input.bin output.lzsa2
;
; Copyright John Brandwood 2021.
;
; Distributed under the Boost Software License, Version 1.0.
; Boost Software License - Version 1.0 - August 17th, 2003
;
; Permission is hereby granted, free of charge, to any person or organization
; obtaining a copy of the software and accompanying documentation covered by
; this license (the "Software") to use, reproduce, display, distribute,
; execute, and transmit the Software, and to prepare derivative works of the
; Software, and to permit third-parties to whom the Software is furnished to
; do so, all subject to the following:
;
; The copyright notices in the Software and this entire statement, including
; the above license grant, this restriction and the following disclaimer,
; must be included in all copies of the Software, in whole or in part, and
; all derivative works of the Software, unless such copies or derivative
; works are solely in the form of machine-executable object code generated by
; a source language processor.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
; SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
; FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
.export _decompress_lzsa2
.import popax
.importzp ptr1, ptr2, ptr3, ptr4, tmp1, tmp2, tmp3
lzsa_length = lzsa_winptr ; 1 word.
lzsa_cmdbuf = tmp1 ; 1 byte.
lzsa_nibflg = tmp2 ; 1 byte.
lzsa_nibble = tmp3 ; 1 byte.
lzsa_offset = ptr1 ; 1 word.
lzsa_winptr = ptr2 ; 1 word.
lzsa_srcptr = ptr3 ; 1 word.
lzsa_dstptr = ptr4 ; 1 word.
.proc _decompress_lzsa2
sta lzsa_dstptr
stx lzsa_dstptr+1
jsr popax
sta lzsa_srcptr
stx lzsa_srcptr+1
lzsa2_unpack:
ldx #$00 ; Hi-byte of length or offset.
ldy #$00 ; Initialize source index.
sty lzsa_nibflg ; Initialize nibble buffer.
;
; Copy bytes from compressed source data.
;
; N.B. X=0 is expected and guaranteed when we get here.
;
cp_length:
lda (lzsa_srcptr),y
inc lzsa_srcptr
bne cp_skip0
inc lzsa_srcptr+1
cp_skip0:
sta lzsa_cmdbuf ; Preserve this for later.
and #$18 ; Extract literal length.
beq lz_offset ; Skip directly to match?
lsr ; Get 2-bit literal length.
lsr
lsr
cmp #$03 ; Extended length?
bcc cp_got_len
jsr get_length ; X=0 for literals, returns CC.
stx cp_npages+1 ; Hi-byte of length.
cp_got_len:
tax ; Lo-byte of length.
cp_byte:
lda (lzsa_srcptr),y ; CC throughout the execution of
sta (lzsa_dstptr),y ; of this .cp_page loop.
inc lzsa_srcptr
bne cp_skip1
inc lzsa_srcptr+1
cp_skip1:
inc lzsa_dstptr
bne cp_skip2
inc lzsa_dstptr+1
cp_skip2:
dex
bne cp_byte
cp_npages:
lda #0 ; Any full pages left to copy?
beq lz_offset
dec cp_npages+1 ; Unlikely, so can be slow
bcc cp_byte ; Always true!
;
; Copy bytes from decompressed window.
;
; N.B. X=0 is expected and guaranteed when we get here.
;
; xyz
; ===========================
; 00z 5-bit offset
; 01z 9-bit offset
; 10z 13-bit offset
; 110 16-bit offset
; 111 repeat offset
;
lz_offset:
lda lzsa_cmdbuf
asl
bcs get_13_16_rep
get_5_9_bits:
dex ; X=$FF for a 5-bit offset.
asl
bcs get_9_bits ; Fall through if 5-bit.
get_13_bits:
asl ; Both 5-bit and 13-bit read
php ; a nibble.
jsr get_nibble
plp
rol ; Shift into position, clr C.
eor #$E1
cpx #$00 ; X=$FF for a 5-bit offset.
bne set_offset
sbc #2 ; 13-bit offset from $FE00.
bne set_hi_8 ; Always NZ from previous SBC.
get_9_bits:
asl ; X=$FF if CC, X=$FE if CS.
bcc get_lo_8
dex
bcs get_lo_8 ; Always CS from previous BCC.
get_13_16_rep:
asl
bcc get_13_bits ; Shares code with 5-bit path.
get_16_rep:
bmi lz_length ; Repeat previous offset.
get_16_bits:
jsr get_byte ; Get hi-byte of offset.
set_hi_8:
tax
get_lo_8:
lda (lzsa_srcptr),y ; Get lo-byte of offset.
inc lzsa_srcptr
bne set_offset
inc lzsa_srcptr+1
set_offset:
sta lzsa_offset ; Save new offset.
stx lzsa_offset+1
lz_length:
ldx #1 ; Hi-byte of length+256.
lda lzsa_cmdbuf
and #$07
clc
adc #$02
cmp #$09 ; Extended length?
bcc got_lz_len
jsr get_length ; X=1 for match, returns CC.
inx ; Hi-byte of length+256.
got_lz_len:
eor #$FF ; Negate the lo-byte of length.
tay
eor #$FF
get_lz_dst:
adc lzsa_dstptr ; Calc address of partial page.
sta lzsa_dstptr ; Always CC from previous CMP.
iny
bcs get_lz_win
beq get_lz_win ; Is lo-byte of length zero?
dec lzsa_dstptr+1
get_lz_win:
clc ; Calc address of match.
adc lzsa_offset ; N.B. Offset is negative!
sta lzsa_winptr
lda lzsa_dstptr+1
adc lzsa_offset+1
sta lzsa_winptr+1
lz_byte:
lda (lzsa_winptr),y
sta (lzsa_dstptr),y
iny
bne lz_byte
inc lzsa_dstptr+1
dex ; Any full pages left to copy?
bne lz_more
jmp cp_length ; Loop around to the beginning.
lz_more:
inc lzsa_winptr+1 ; Unlikely, so can be slow.
bne lz_byte ; Always true!
;
; Lookup tables to differentiate literal and match lengths.
;
nibl_len_tbl:
.byte 3 ; 0+3 (for literal).
.byte 9 ; 2+7 (for match).
byte_len_tbl:
.byte 18 - 1 ; 0+3+15 - CS (for literal).
.byte 24 - 1 ; 2+7+15 - CS (for match).
;
; Get 16-bit length in X:A register pair, return with CC.
;
get_length:
jsr get_nibble
cmp #$0F ; Extended length?
bcs byte_length
adc nibl_len_tbl,x ; Always CC from previous CMP.
got_length:
ldx #$00 ; Set hi-byte of 4 & 8 bit
rts ; lengths.
byte_length:
jsr get_byte ; So rare, this can be slow!
adc byte_len_tbl,x ; Always CS from previous CMP
bcc got_length
beq finished
word_length:
clc ; MUST return CC!
jsr get_byte ; So rare, this can be slow!
pha
jsr get_byte ; So rare, this can be slow!
tax
pla
bne got_word ; Check for zero lo-byte.
dex ; Do one less page loop if so.
got_word:
rts
get_byte:
lda (lzsa_srcptr),y ; Subroutine version for when
inc lzsa_srcptr ; inlining isn't advantageous.
bne got_byte
inc lzsa_srcptr+1
got_byte:
rts
finished:
pla ; Decompression completed, pop
pla ; return address.
rts
;
; Get a nibble value from compressed data in A.
;
get_nibble:
lsr lzsa_nibflg ; Is there a nibble waiting?
lda lzsa_nibble ; Extract the lo-nibble.
bcs got_nibble
inc lzsa_nibflg ; Reset the flag.
lda (lzsa_srcptr),y
inc lzsa_srcptr
bne set_nibble
inc lzsa_srcptr+1
set_nibble:
sta lzsa_nibble ; Preserve for next time.
lsr ; Extract the hi-nibble.
lsr
lsr
lsr
got_nibble:
and #$0F
rts
.endproc

148
libsrc/common/zx02.s Normal file
View File

@@ -0,0 +1,148 @@
; void __fastcall__ decompress_zx02(const void *src, void *dest)
;
; De-compressor for ZX02 files
;
; Compress with:
; zx02 input.bin output.zx0
;
; (c) 2022 DMSC
; Code under MIT license, see LICENSE file.
.export _decompress_zx02
.import popax
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
offset_hi = tmp1
ZX0_src = ptr1
ZX0_dst = ptr2
bitr = tmp2
pntr = ptr3
.proc _decompress_zx02
sta ZX0_dst
stx ZX0_dst+1
jsr popax
sta ZX0_src
stx ZX0_src+1
; Init values
lda #$80
sta bitr
ldy #$FF
sty pntr
iny
sty offset_hi ; Y = 0 at end of init
; Decode literal: Copy next N bytes from compressed file
; Elias(length) byte[1] byte[2] ... byte[N]
decode_literal:
ldx #$01
jsr get_elias
cop0:
lda (ZX0_src), y
inc ZX0_src
bne :+
inc ZX0_src+1
: sta (ZX0_dst),y
inc ZX0_dst
bne :+
inc ZX0_dst+1
: dex
bne cop0
asl bitr
bcs dzx0s_new_offset
; Copy from last offset (repeat N bytes from last offset)
; Elias(length)
inx
jsr get_elias
dzx0s_copy:
lda ZX0_dst+1
sbc offset_hi ; C=0 from get_elias
sta pntr+1
cop1:
ldy ZX0_dst
lda (pntr), y
ldy #0
sta (ZX0_dst),y
inc ZX0_dst
bne :+
inc ZX0_dst+1
inc pntr+1
: dex
bne cop1
asl bitr
bcc decode_literal
; Copy from new offset (repeat N bytes from new offset)
; Elias(MSB(offset)) LSB(offset) Elias(length-1)
dzx0s_new_offset:
; Read elias code for high part of offset
inx
jsr get_elias
beq exit ; Read a 0, signals the end
; Decrease and divide by 2
dex
txa
lsr
sta offset_hi
; Get low part of offset, a literal 7 bits
lda (ZX0_src), y
inc ZX0_src
bne :+
inc ZX0_src+1
: ; Divide by 2
ror
eor #$ff
sta pntr
; And get the copy length.
; Start elias reading with the bit already in carry:
ldx #1
jsr elias_skip1
inx
bcc dzx0s_copy
; Read an elias-gamma interlaced code.
elias_get:
; Read next data bit to result
asl bitr
rol
tax
get_elias:
; Get one bit
asl bitr
bne elias_skip1
; Read new bit from stream
lda (ZX0_src), y
inc ZX0_src
bne :+
inc ZX0_src+1
: ; sec ; not needed, C=1 guaranteed from last bit
rol
sta bitr
elias_skip1:
txa
bcs elias_get
; Got ending bit, stop reading
exit:
rts
.endproc

View File

@@ -9,11 +9,11 @@
.export _textcolor, _bgcolor, _bordercolor
.import return0, ppubuf_put
.import return0, return1, ppubuf_put
.include "nes.inc"
_textcolor = return0
_textcolor = return1
_bordercolor = return0
.proc _bgcolor

37
libsrc/nes/cpeekc.s Normal file
View File

@@ -0,0 +1,37 @@
;
; 2016-02-28, Groepaz
; 2017-08-17, Greg King
;
; char cpeekc (void);
;
.export _cpeekc
.import ppubuf_waitempty
.forceimport initconio
.include "nes.inc"
_cpeekc:
; wait until all console data has been written
jsr ppubuf_waitempty
ldy SCREEN_PTR+1
lda SCREEN_PTR
; waiting for vblank is incredibly slow ://
vwait:
; ldx PPU_STATUS
; bpl vwait
ldx #>$0000
sty PPU_VRAM_ADDR2
sta PPU_VRAM_ADDR2
lda PPU_VRAM_IO ; first read is invalid
lda PPU_VRAM_IO ; get data
stx PPU_VRAM_ADDR2
stx PPU_VRAM_ADDR2
and #<~$80 ; remove reverse bit
rts

8
libsrc/nes/cpeekcolor.s Normal file
View File

@@ -0,0 +1,8 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

37
libsrc/nes/cpeekrevers.s Normal file
View File

@@ -0,0 +1,37 @@
;
; 2016-02-28, Groepaz
; 2017-08-17, Greg King
;
; char cpeekrevers (void);
;
.export _cpeekrevers
.import ppubuf_waitempty
.forceimport initconio
.include "nes.inc"
_cpeekrevers:
; wait until all console data has been written
jsr ppubuf_waitempty
ldy SCREEN_PTR+1
lda SCREEN_PTR
; waiting for vblank is incredibly slow ://
vwait:
; ldx PPU_STATUS
; bpl vwait
ldx #>$0000
sty PPU_VRAM_ADDR2
sta PPU_VRAM_ADDR2
lda PPU_VRAM_IO ; first read is invalid
lda PPU_VRAM_IO ; get data
stx PPU_VRAM_ADDR2
stx PPU_VRAM_ADDR2
and #<$80 ; get reverse bit
rts

17
libsrc/osic1p/cpeekc.s Normal file
View File

@@ -0,0 +1,17 @@
;
; 2017-06-21, Greg King
;
; char cpeekc (void);
;
; Get a character from OSI C1P screen RAM.
;
.export _cpeekc
.include "extzp.inc"
_cpeekc:
ldy CURS_X
lda (SCREEN_PTR),y
ldx #>$0000
rts

View File

@@ -0,0 +1,8 @@
;
; 2017-06-03, Greg King
;
; unsigned char cpeekcolor (void);
;
.import return1
.export _cpeekcolor := return1 ; always COLOR_WHITE

View File

@@ -0,0 +1,9 @@
;
; 2017-06-15, Greg King
;
; unsigned char cpeekrevers (void);
;
; Get a reverse attribute from screen RAM
;
.import return0
.export _cpeekrevers := return0 ; No attribute

View File

@@ -14,11 +14,11 @@ _cpeekc:
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
lda VDC_DATA_LO ; character
lda a:VDC_DATA_LO ; character
and #<~$80 ; remove reverse bit
ldx #0
rts

View File

@@ -14,11 +14,11 @@ _cpeekcolor:
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
lda VDC_DATA_HI
lda a:VDC_DATA_HI
and #<~$02
lsr a
lsr a

View File

@@ -14,13 +14,14 @@ _cpeekrevers:
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
lda VDC_DATA_LO ; character (bit 7 is revers bit)
rol a
rol a
and #1
ldx #0
lda a:VDC_DATA_LO ; character (bit 7 is revers bit)
and #$80 ; get reverse bit
asl a ; reverse bit to carry, A=0
tax ; ldx #>$0000
rol a ; reverse bit from carry
rts

View File

@@ -1,5 +1,6 @@
;
; 2020-07-14, Groepaz
; 2020-07-15, Greg King
;
; void cpeeks (char* s, unsigned length);
;
@@ -8,9 +9,7 @@
.export _cpeeks
.import popax
.importzp ptr1, ptr2, tmp1, tmp2
.macpack generic
.importzp ptr1, ptr2
.include "pce.inc"
.include "extzp.inc"
@@ -22,35 +21,31 @@ _cpeeks:
eor #>$FFFF
sta ptr2+1
st0 #VDC_CR ; Control Register
st2 #>$0088 ; make VRAM address increment by one
st0 #VDC_MARR ; Memory-Address Read
ldy SCREEN_PTR
ldx SCREEN_PTR+1
sty VDC_DATA_LO
stx VDC_DATA_HI
sty a:VDC_DATA_LO
stx a:VDC_DATA_HI
st0 #VDC_VRR ; VRAM Read Register
jsr popax
sta tmp1 ; (will be a .Y index)
tay ; low byte of address will be used as index
stx ptr1+1
ldx #<$0000
stx ptr1
beq L2 ; branch always
L3: ldy tmp2
lda VDC_DATA_LO ; get character
bit VDC_DATA_HI ; we need to "read" the highbyte to advance the address
iny
sty tmp2
L3: lda a:VDC_DATA_LO ; get character
bit a:VDC_DATA_HI ; need to read high byte to advance VDC address
and #<~$80 ; remove reverse bit
ldy tmp1
sta (ptr1),y
iny
bne L1
bne L2
inc ptr1+1
L1: sty tmp1
L2: inc ptr2 ; count length
bne L3
@@ -58,6 +53,5 @@ L2: inc ptr2 ; count length
bne L3
txa ; terminate the string
ldy tmp1
sta (ptr1),y
rts

17
libsrc/plus4/kgetin.s Normal file
View File

@@ -0,0 +1,17 @@
.export GETIN
.scope KERNAL
.include "cbm_kernal.inc"
.endscope
.include "plus4.inc"
.segment "LOWCODE" ; Stay out of ROM area.
.proc GETIN
sta ENABLE_ROM
jsr KERNAL::GETIN
sta ENABLE_RAM
rts
.endproc

View File

@@ -1,6 +1,7 @@
;
; 2001-11-14, Piotr Fusik
; 2018-05-20, Christian Kruger
; 2025-05-14, Piotr Fusik
;
; unsigned long __fastcall__ crc32 (unsigned long crc,
; const unsigned char* buf,
@@ -9,7 +10,7 @@
.export _crc32
.import compleax, incsp2, incsp4, popptr1, popeax
.import compleax, incsp4, popptr1, popeax
.importzp sreg, ptr1, ptr2, tmp1, tmp2
POLYNOMIAL = $EDB88320
@@ -58,15 +59,12 @@ make_table:
inx
bne @L1
inc table_initialised
RET:
rts
_crc32:
; ptr2 = (len & 0xff) == 0 ? len : len + 0x100;
tay
beq @L1
; ptr2 = len + 0x100
inx
@L1: sta ptr2
sta ptr2
stx ptr2+1
; ptr1 = buf
jsr popptr1
@@ -78,20 +76,15 @@ _crc32:
bne @dont_make
jsr make_table
@dont_make:
; eax = crc
jsr popeax
; if (len == 0) return crc;
ldy ptr2
bne @L2
ldy ptr2+1
beq RET
@L2:
; eax = ~crc
jsr popeax
jsr compleax
stx tmp2
ldy #0
@L1: cpy ptr2
beq @low_end
; crc = (crc >> 8) ^ table[(crc & 0xff) ^ *p++];
@L3: eor (ptr1),y
@L2: eor (ptr1),y
tax
lda table_0,x
eor tmp2
@@ -106,12 +99,12 @@ _crc32:
sta sreg+1
lda tmp1
iny
bne @L4
bne @L1
inc ptr1+1
@L4: dec ptr2
bne @L3
jmp @L1
@low_end:
dec ptr2+1
bne @L3
bne @L2
ldx tmp2
jmp compleax