mirror of
https://github.com/KarolS/millfork.git
synced 2024-11-01 21:04:51 +00:00
184 lines
3.6 KiB
Plaintext
184 lines
3.6 KiB
Plaintext
#if ENCODING_SAME
|
|
|
|
#if ARCH_6502
|
|
inline byte __byte_identity(byte a) { ? rts }
|
|
inline void __pointer_to_void(pointer ax) { ? rts }
|
|
#elseif ARCH_I80
|
|
#pragma zilog_syntax
|
|
inline byte __byte_identity(byte a) { ? ret }
|
|
inline void __pointer_to_void(pointer hl) { ? ret }
|
|
#elseif ARCH_M6809
|
|
inline byte __byte_identity(byte b) { ? rts }
|
|
inline void __pointer_to_void(pointer d) { ? rts }
|
|
#else
|
|
inline byte __byte_identity(byte a) = a
|
|
inline void __pointer_to_void(pointer a) { }
|
|
#endif
|
|
|
|
alias from_screencode = __byte_identity
|
|
alias to_screencode = __byte_identity
|
|
alias strz_from_screencode = __pointer_to_void
|
|
alias strz_to_screencode = __pointer_to_void
|
|
|
|
#elseif ENCCONV_SUPPORTED
|
|
|
|
alias from_screencode = __from_screencode
|
|
alias to_screencode = __to_screencode
|
|
|
|
|
|
#if ARCH_6502
|
|
void strz_from_screencode(pointer p) {
|
|
asm {
|
|
? LDY #0
|
|
__strz_from_screencode__loop:
|
|
LDA (p),Y
|
|
? CMP #nullchar_scr
|
|
? BEQ __strz_from_screencode__end
|
|
? JSR from_screencode
|
|
? STA (p),Y
|
|
? INY
|
|
? JMP __strz_from_screencode__loop
|
|
__strz_from_screencode__end:
|
|
? LDA #nullchar
|
|
? STA (p),Y
|
|
}
|
|
}
|
|
void strz_to_screencode(pointer p) {
|
|
asm {
|
|
? LDY #0
|
|
__strz_to_screencode__loop:
|
|
LDA (p),Y
|
|
? CMP #nullchar
|
|
? BEQ __strz_to_screencode__end
|
|
? JSR to_screencode
|
|
? STA (p),Y
|
|
? INY
|
|
? JMP __strz_to_screencode__loop
|
|
__strz_to_screencode__end:
|
|
? LDA #nullchar_scr
|
|
? STA (p),Y
|
|
}
|
|
}
|
|
#else
|
|
void strz_from_screencode(pointer p) {
|
|
while true {
|
|
if p[0] == nullchar_scr {
|
|
p[0] = nullchar
|
|
return
|
|
}
|
|
p[0] = from_screencode(p[0])
|
|
p += 1
|
|
}
|
|
}
|
|
void strz_to_screencode(pointer p) {
|
|
while true {
|
|
if p[0] == nullchar {
|
|
p[0] = nullchar_scr
|
|
return
|
|
}
|
|
p[0] = to_screencode(p[0])
|
|
p += 1
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#endif // ENCODING_SAME/ENCCONV_SUPPORTED
|
|
|
|
|
|
// conversions for particular encoding pairs:
|
|
|
|
#if ARCH_6502
|
|
|
|
asm byte petscii_to_petscr(byte a) {
|
|
cmp #$20
|
|
bcc __petscii_to_petscr_ddRev
|
|
cmp #$60
|
|
bcc __petscii_to_petscr_dd1
|
|
cmp #$80
|
|
bcc __petscii_to_petscr_dd2
|
|
cmp #$a0
|
|
bcc __petscii_to_petscr_dd3
|
|
cmp #$c0
|
|
bcc __petscii_to_petscr_dd4
|
|
cmp #$ff
|
|
bcc __petscii_to_petscr_ddRev
|
|
lda #$5e
|
|
rts
|
|
__petscii_to_petscr_dd2:
|
|
and #$5f
|
|
rts
|
|
__petscii_to_petscr_dd3:
|
|
ora #$40
|
|
rts
|
|
__petscii_to_petscr_dd4:
|
|
eor #$c0
|
|
rts
|
|
__petscii_to_petscr_dd1:
|
|
and #$3f
|
|
rts
|
|
__petscii_to_petscr_ddRev:
|
|
eor #$80
|
|
rts
|
|
}
|
|
|
|
asm byte petscr_to_petscii(byte a) {
|
|
cmp #$20
|
|
bcs __petscr_to_petscii_40
|
|
ora #$40
|
|
rts
|
|
__petscr_to_petscii_40:
|
|
cmp #$40
|
|
bcs __petscr_to_petscii_60
|
|
rts
|
|
__petscr_to_petscii_60:
|
|
cmp #$60
|
|
bcs __petscr_to_petscii_80
|
|
eor #$80
|
|
rts
|
|
__petscr_to_petscii_80:
|
|
cmp #$80
|
|
bcs __petscr_to_petscii_a0
|
|
eor #$c0
|
|
rts
|
|
__petscr_to_petscii_a0:
|
|
cmp #$a0
|
|
bcs __petscr_to_petscii_c0
|
|
eor #$80
|
|
rts
|
|
__petscr_to_petscii_c0:
|
|
eor #$40
|
|
rts
|
|
}
|
|
|
|
asm byte atascii_to_atasciiscr(byte a) {
|
|
and #$7f
|
|
cmp #$20
|
|
bcs __atascii_to_atasciiscr_60
|
|
ora #$40
|
|
rts
|
|
__atascii_to_atasciiscr_60:
|
|
cmp #$60
|
|
bcs __atascii_to_atasciiscr_end
|
|
sec
|
|
sbc #$20
|
|
__atascii_to_atasciiscr_end:
|
|
rts
|
|
}
|
|
|
|
|
|
asm byte atasciiscr_to_atascii(byte a) {
|
|
and #$7f
|
|
cmp #$40
|
|
bcs __atascii_to_atasciiscr_60
|
|
clc
|
|
adc #$20
|
|
rts
|
|
__atascii_to_atasciiscr_60:
|
|
cmp #$60
|
|
bcs __atascii_to_atasciiscr_end
|
|
and #$1f
|
|
__atascii_to_atasciiscr_end:
|
|
rts
|
|
}
|
|
|
|
#endif |