mirror of
https://github.com/lscharen/iigs-game-engine.git
synced 2025-02-16 10:32:20 +00:00
Add small header to converted image data
This commit is contained in:
parent
9d33ff3000
commit
d9e3ee14e8
131
src/App.Main.s
131
src/App.Main.s
@ -416,10 +416,34 @@ CopyBinToField
|
|||||||
:col_cnt equ tmp5
|
:col_cnt equ tmp5
|
||||||
:mask equ tmp6
|
:mask equ tmp6
|
||||||
:data equ tmp7
|
:data equ tmp7
|
||||||
|
:mask_color equ tmp8
|
||||||
|
|
||||||
sta :srcptr
|
sta :srcptr
|
||||||
stx :srcptr+2
|
stx :srcptr+2
|
||||||
|
|
||||||
|
; Check that this is a GTERAW image and save the transparent color
|
||||||
|
|
||||||
|
ldy #4
|
||||||
|
:chkloop
|
||||||
|
lda [:srcptr],y
|
||||||
|
cmp :headerStr,y
|
||||||
|
beq *+3
|
||||||
|
rts
|
||||||
|
dey
|
||||||
|
dey
|
||||||
|
bpl :chkloop
|
||||||
|
|
||||||
|
; We have a valid header, now get the transparency word and load it in
|
||||||
|
ldy #6
|
||||||
|
lda [:srcptr],y
|
||||||
|
sta :mask_color
|
||||||
|
|
||||||
|
; Advance over the header
|
||||||
|
lda :srcptr
|
||||||
|
clc
|
||||||
|
adc #8
|
||||||
|
sta :srcptr
|
||||||
|
|
||||||
stz :line_cnt
|
stz :line_cnt
|
||||||
:rloop
|
:rloop
|
||||||
lda :line_cnt ; get the pointer to the code field line
|
lda :line_cnt ; get the pointer to the code field line
|
||||||
@ -440,12 +464,15 @@ CopyBinToField
|
|||||||
:cloop
|
:cloop
|
||||||
phy
|
phy
|
||||||
lda [:srcptr],y ; load the picture data
|
lda [:srcptr],y ; load the picture data
|
||||||
|
cmp :mask_color
|
||||||
beq :transparent ; a value of $0000 is transparent
|
beq :transparent ; a value of $0000 is transparent
|
||||||
|
|
||||||
jsr :toMask ; Infer a mask value for this. If it's $0000, then
|
jsr :toMask ; Infer a mask value for this. If it's $0000, then
|
||||||
|
cmp #$0000
|
||||||
bne :mixed ; the data is solid, otherwise mixed
|
bne :mixed ; the data is solid, otherwise mixed
|
||||||
|
|
||||||
; This is a solid word
|
; This is a solid word
|
||||||
|
:solid
|
||||||
lda [:srcptr],y
|
lda [:srcptr],y
|
||||||
ldy Col2CodeOffset,x ; Get the offset to the code from the line start
|
ldy Col2CodeOffset,x ; Get the offset to the code from the line start
|
||||||
|
|
||||||
@ -457,6 +484,10 @@ CopyBinToField
|
|||||||
sta [:dstptr],y ; PEA operand
|
sta [:dstptr],y ; PEA operand
|
||||||
bra :next
|
bra :next
|
||||||
:transparent
|
:transparent
|
||||||
|
lda :mask_color ; Make sure we actually have to mask
|
||||||
|
cmp #$A5A5
|
||||||
|
beq :solid
|
||||||
|
|
||||||
ldy Col2CodeOffset,x ; Get the offset to the code from the line start
|
ldy Col2CodeOffset,x ; Get the offset to the code from the line start
|
||||||
lda #$B1 ; LDA (dp),y
|
lda #$B1 ; LDA (dp),y
|
||||||
sta [:dstptr],y
|
sta [:dstptr],y
|
||||||
@ -494,7 +525,9 @@ CopyBinToField
|
|||||||
iny
|
iny
|
||||||
iny
|
iny
|
||||||
iny ; advance to the ORA #imm operand
|
iny ; advance to the ORA #imm operand
|
||||||
lda :data
|
lda :mask
|
||||||
|
eor #$FFFF ; invert the mask to clear up the data
|
||||||
|
and :data
|
||||||
sta [:dstptr],y
|
sta [:dstptr],y
|
||||||
|
|
||||||
:next
|
:next
|
||||||
@ -522,31 +555,57 @@ CopyBinToField
|
|||||||
:exit
|
:exit
|
||||||
rts
|
rts
|
||||||
|
|
||||||
:toMask bit #$F000
|
:toMask pha ; save original
|
||||||
beq *+7
|
|
||||||
and #$0FFF
|
|
||||||
bra *+5
|
|
||||||
ora #$F000
|
|
||||||
|
|
||||||
bit #$0F00
|
lda 1,s
|
||||||
|
eor :mask_color ; only identical bits produce zero
|
||||||
|
and #$F000
|
||||||
beq *+7
|
beq *+7
|
||||||
and #$F0FF
|
pea #$0000
|
||||||
bra *+5
|
bra *+5
|
||||||
ora #$0F00
|
pea #$F000
|
||||||
|
|
||||||
bit #$00F0
|
|
||||||
beq *+7
|
|
||||||
and #$FF0F
|
|
||||||
bra *+5
|
|
||||||
ora #$00F0
|
|
||||||
|
|
||||||
bit #$000F
|
lda 3,s
|
||||||
|
eor :mask_color
|
||||||
|
and #$0F00
|
||||||
beq *+7
|
beq *+7
|
||||||
and #$FFF0
|
pea #$0000
|
||||||
bra *+5
|
bra *+5
|
||||||
ora #$000F
|
pea #$0F00
|
||||||
|
|
||||||
|
lda 5,s
|
||||||
|
eor :mask_color
|
||||||
|
and #$00F0
|
||||||
|
beq *+7
|
||||||
|
pea #$0000
|
||||||
|
bra *+5
|
||||||
|
pea #$00F0
|
||||||
|
|
||||||
|
lda 7,s
|
||||||
|
eor :mask_color
|
||||||
|
and #$000F
|
||||||
|
beq *+7
|
||||||
|
lda #$0000
|
||||||
|
bra *+5
|
||||||
|
lda #$000F
|
||||||
|
|
||||||
|
ora 1,s
|
||||||
|
sta 1,s
|
||||||
|
pla
|
||||||
|
ora 1,s
|
||||||
|
sta 1,s
|
||||||
|
pla
|
||||||
|
ora 1,s
|
||||||
|
sta 1,s
|
||||||
|
pla
|
||||||
|
|
||||||
|
sta 1,s ; pop the saved word
|
||||||
|
pla
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
:headerStr asc 'GTERAW'
|
||||||
|
|
||||||
; Copy a loaded SHR picture into the code field
|
; Copy a loaded SHR picture into the code field
|
||||||
;
|
;
|
||||||
; A=low word of picture address
|
; A=low word of picture address
|
||||||
@ -710,6 +769,12 @@ CopyBinToBG1
|
|||||||
stx :srcptr+2
|
stx :srcptr+2
|
||||||
sty :dstptr+2 ; Everything goes into this bank
|
sty :dstptr+2 ; Everything goes into this bank
|
||||||
|
|
||||||
|
; Advance over the header
|
||||||
|
lda :srcptr
|
||||||
|
clc
|
||||||
|
adc #8
|
||||||
|
sta :srcptr
|
||||||
|
|
||||||
stz :line_cnt
|
stz :line_cnt
|
||||||
:rloop
|
:rloop
|
||||||
lda :line_cnt ; get the pointer to the code field line
|
lda :line_cnt ; get the pointer to the code field line
|
||||||
@ -843,8 +908,14 @@ GrafInit
|
|||||||
dw $0fa9,$0ff0,$00e0,$04DF
|
dw $0fa9,$0ff0,$00e0,$04DF
|
||||||
dw $0d00,$078f,$0ccc,$0FFF
|
dw $0d00,$078f,$0ccc,$0FFF
|
||||||
|
|
||||||
|
; Super Mario World Assets
|
||||||
DefaultPalette dw $0EEF,$0342,$0C95,$0852,$0DB4,$00C0
|
DefaultPalette dw $0EEF,$0342,$0C95,$0852,$0DB4,$00C0
|
||||||
dw $0FDA,$0DEE,$0000,$0CC5,$09A0,$0680,$0470,$0051
|
dw $0FDA,$0DEE,$0000,$0CC5,$09A0,$0680,$0470,$0051
|
||||||
|
|
||||||
|
;DefaultPalette dw $0000,$0000,$0778,$0BCC,$0368,$00AF,$0556,$0245
|
||||||
|
dw $0000,$0778,$0AAA,$0CFF,$0368,$00AF,$0556
|
||||||
|
|
||||||
|
|
||||||
; Return the current border color ($0 - $F) in the accumulator
|
; Return the current border color ($0 - $F) in the accumulator
|
||||||
GetBorderColor lda #0000
|
GetBorderColor lda #0000
|
||||||
sep #$20
|
sep #$20
|
||||||
@ -1170,6 +1241,32 @@ qtRec adrl $0000
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ const { Buffer } = require('buffer');
|
|||||||
|
|
||||||
// Starting color index
|
// Starting color index
|
||||||
let startIndex = 0;
|
let startIndex = 0;
|
||||||
|
let transparentColor = 0;
|
||||||
|
|
||||||
main(process.argv.slice(2)).then(
|
main(process.argv.slice(2)).then(
|
||||||
() => process.exit(0),
|
() => process.exit(0),
|
||||||
@ -110,6 +111,7 @@ async function main(argv) {
|
|||||||
const data = await fs.readFile(argv[0]);
|
const data = await fs.readFile(argv[0]);
|
||||||
const png = PNG.sync.read(data);
|
const png = PNG.sync.read(data);
|
||||||
startIndex = getArg(argv, '--start-index', x => parseInt(x, 10), 0);
|
startIndex = getArg(argv, '--start-index', x => parseInt(x, 10), 0);
|
||||||
|
transparentColor = getArg(argv, '--transparent-color-index', x => parseInt(x, 10), 0);
|
||||||
|
|
||||||
console.info(`startIndex = ${startIndex}`);
|
console.info(`startIndex = ${startIndex}`);
|
||||||
|
|
||||||
@ -147,7 +149,22 @@ async function main(argv) {
|
|||||||
|
|
||||||
if (buff && argv[1]) {
|
if (buff && argv[1]) {
|
||||||
console.log(`Writing to output file ${argv[1]}`);
|
console.log(`Writing to output file ${argv[1]}`);
|
||||||
await fs.writeFile(argv[1], buff);
|
|
||||||
|
// Write a small header. This is useful and avoids triggering a sparse file load
|
||||||
|
// bug when the first block of the file on the GS/OS drive is sparse.
|
||||||
|
|
||||||
|
// Put the ASCII text of "GTERAW" in the first 6 bytes
|
||||||
|
const header = Buffer.alloc(8);
|
||||||
|
header.write('GTERAW', 'latin1');
|
||||||
|
|
||||||
|
// Use the special value $A5A5 to identify no transparency
|
||||||
|
if (typeof transparentColor !== 'number') {
|
||||||
|
header.writeUInt16LE(0xA5A5);
|
||||||
|
} else {
|
||||||
|
header.writeUInt16LE(0x1111 * transparentColor, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(argv[1], Buffer.concat([header, buff]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user