Added support for the color white

This commit is contained in:
Quinn Dunki 2016-12-21 14:03:28 -08:00
parent a37f15846f
commit 7eb3f6fdd7
13 changed files with 3175 additions and 1005 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ hgrtest.lst
HGR.xcodeproj/project.xcworkspace/xcuserdata/qd.xcuserdatad/UserInterfaceState.xcuserstate HGR.xcodeproj/project.xcworkspace/xcuserdata/qd.xcuserdatad/UserInterfaceState.xcuserstate
/.DS_Store /.DS_Store
/hisprite.lst /hisprite.lst
/HiSprite.xcodeproj/project.xcworkspace/xcuserdata/qd.xcuserdatad/UserInterfaceState.xcuserstate
/HiSprite.xcodeproj/xcuserdata/qd.xcuserdatad/xcdebugger

View File

@ -3,7 +3,7 @@
import sys,os,png import sys,os,png
class Colors: class Colors:
black,magenta,green,orange,blue = range(5) black,magenta,green,orange,blue,white = range(6)
@ -29,16 +29,19 @@ def main(argv):
disclaimer() disclaimer()
# Prologue
print "%s: ;%d bytes per row" % (niceName,byteWidth) print "%s: ;%d bytes per row" % (niceName,byteWidth)
print "\tSAVE_AXY" print "\tSAVE_AXY"
print "\tldy PARAM0" print "\tldy PARAM0"
print "\tldx MOD7_2,y" print "\tldx MOD7_2,y"
print "\tjmp (%s_JMP,x)\n" % (niceName) print "\tjmp (%s_JMP,x)\n" % (niceName)
# Bit-shift jump table
print "%s_JMP:" % (niceName) print "%s_JMP:" % (niceName)
for shift in range(0,7): for shift in range(0,7):
print "\t.addr %s_SHIFT%d" % (niceName,shift) print "\t.addr %s_SHIFT%d" % (niceName,shift)
# Blitting functions
print "\n" print "\n"
for shift in range(0,7): for shift in range(0,7):
print "%s_SHIFT%d:" % (niceName,shift) print "%s_SHIFT%d:" % (niceName,shift)
@ -64,23 +67,30 @@ def layoutSpriteChunk(pixeldata,width,height,shift):
byteWidth = width/2+1+1 # TODO: Calculate a power of two for this byteWidth = width/2+1+1 # TODO: Calculate a power of two for this
spriteChunks = [["" for y in range(height)] for x in range(byteWidth)] spriteChunks = [["" for y in range(height)] for x in range(byteWidth)]
# Layout rows
for row in range(height): for row in range(height):
pixelRow = bitmap[row] pixelRow = bitmap[row]
bitStream = "" bitStream = ""
# Compute raw bitstream for row from PNG pixels
for pixelIndex in range(width): for pixelIndex in range(width):
pixel = pixelColor(pixeldata,row,pixelIndex) pixel = pixelColor(pixeldata,row,pixelIndex)
if pixel == Colors.black: if pixel == Colors.black:
bitStream += "00" bitStream += "00"
else: else:
if pixel == Colors.green or pixel == Colors.orange: if pixel == Colors.white:
bitStream += "01" bitStream += "11"
else: else:
bitStream += "10" if pixel == Colors.green or pixel == Colors.orange:
bitStream += "01"
else:
bitStream += "10"
# Shift bit stream as needed
bitStream = shiftStringRight(bitStream,shift) bitStream = shiftStringRight(bitStream,shift)
bitStream = bitStream[:byteWidth*8] bitStream = bitStream[:byteWidth*8]
# Split bitstream into bytes
bitPos = 0 bitPos = 0
byteSplits = [0 for x in range(byteWidth)] byteSplits = [0 for x in range(byteWidth)]
@ -99,26 +109,33 @@ def layoutSpriteChunk(pixeldata,width,height,shift):
bitChunk = bitStream[bitPos:bitPos+7] bitChunk = bitStream[bitPos:bitPos+7]
bitChunk = bitChunk[::-1] bitChunk = bitChunk[::-1]
# Set palette bit as needed. Note that we prefer high-bit white
# because blue fringe is less noticeable than magenta
highBit = "0" highBit = "0"
if pixel == Colors.orange or pixel == Colors.blue: if pixel == Colors.orange or pixel == Colors.blue or pixel == Colors.white:
highBit = "1" highBit = "1"
byteSplits[byteIndex] = highBit + bitChunk byteSplits[byteIndex] = highBit + bitChunk
bitPos += 7 bitPos += 7
# Generate blitting code
for chunkIndex in range(len(byteSplits)): for chunkIndex in range(len(byteSplits)):
if (not byteSplits[chunkIndex].endswith("0000000")):
# Store byte into video memory
if (not byteSplits[chunkIndex].endswith("0000000")): # Optimization- don't render all-black bytes
spriteChunks[chunkIndex][row] = \ spriteChunks[chunkIndex][row] = \
"\tlda #%%%s\n" % byteSplits[chunkIndex] + \ "\tlda #%%%s\n" % byteSplits[chunkIndex] + \
"\tora (SCRATCH0),y\n" + \ "\tora (SCRATCH0),y\n" + \
"\tsta (SCRATCH0),y\n"; "\tsta (SCRATCH0),y\n";
# Increment indices
if chunkIndex == len(byteSplits)-1: if chunkIndex == len(byteSplits)-1:
spriteChunks[chunkIndex][row] += "\n" spriteChunks[chunkIndex][row] += "\n"
else: else:
spriteChunks[chunkIndex][row] += "\tiny" spriteChunks[chunkIndex][row] += "\tiny"
# Finish the row
if row<height-1: if row<height-1:
spriteChunks[chunkIndex][row] += "\tinx\n" + rowStartCalculatorCode(); spriteChunks[chunkIndex][row] += "\tinx\n" + rowStartCalculatorCode();
else: else:
@ -177,7 +194,9 @@ def pixelColor(pixeldata,row,col):
else: else:
if r==255 and g>0 and b==0: if r==255 and g>0 and b==0:
color = Colors.orange color = Colors.orange
else:
if r==255 and g==255 and b==255:
color = Colors.white
return color return color
@ -204,7 +223,7 @@ PNG file must not have an alpha channel!
def disclaimer(): def disclaimer():
print ''' print '''
; This file was generated by SpriteGenerator.py, a sprite generation tool by Quinn Dunki. ; This file was generated by HiSprite.py, a sprite compiler by Quinn Dunki.
; If you feel the need to modify this file, you are probably doing it wrong. ; If you feel the need to modify this file, you are probably doing it wrong.
''' '''
return return
@ -212,4 +231,4 @@ def disclaimer():
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])

View File

@ -17,6 +17,8 @@
701B5E151D84823300E6D330 /* spritegen2.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = spritegen2.s; sourceTree = "<group>"; }; 701B5E151D84823300E6D330 /* spritegen2.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = spritegen2.s; sourceTree = "<group>"; };
701B5E161D84823300E6D330 /* spritegen3.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = spritegen3.s; sourceTree = "<group>"; }; 701B5E161D84823300E6D330 /* spritegen3.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = spritegen3.s; sourceTree = "<group>"; };
701B5E171D84824400E6D330 /* hgrtableY.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = hgrtableY.s; sourceTree = "<group>"; }; 701B5E171D84824400E6D330 /* hgrtableY.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = hgrtableY.s; sourceTree = "<group>"; };
701B5E181D849F3800E6D330 /* graphics.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = graphics.s; sourceTree = "<group>"; };
70A65D491E0B137D00FB9D02 /* spritegen4.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = spritegen4.s; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
@ -27,12 +29,14 @@
701B5E111D84817500E6D330 /* HiSprite.py */, 701B5E111D84817500E6D330 /* HiSprite.py */,
701B5E0E1D84810000E6D330 /* macros.s */, 701B5E0E1D84810000E6D330 /* macros.s */,
701B5E101D84813500E6D330 /* hisprite.s */, 701B5E101D84813500E6D330 /* hisprite.s */,
701B5E181D849F3800E6D330 /* graphics.s */,
701B5E121D8481C800E6D330 /* hgrtableX.s */, 701B5E121D8481C800E6D330 /* hgrtableX.s */,
701B5E171D84824400E6D330 /* hgrtableY.s */, 701B5E171D84824400E6D330 /* hgrtableY.s */,
701B5E131D84820100E6D330 /* spritegen0.s */, 701B5E131D84820100E6D330 /* spritegen0.s */,
701B5E141D84823300E6D330 /* spritegen1.s */, 701B5E141D84823300E6D330 /* spritegen1.s */,
701B5E151D84823300E6D330 /* spritegen2.s */, 701B5E151D84823300E6D330 /* spritegen2.s */,
701B5E161D84823300E6D330 /* spritegen3.s */, 701B5E161D84823300E6D330 /* spritegen3.s */,
70A65D491E0B137D00FB9D02 /* spritegen4.s */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };

BIN
boxw_mag.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

BIN
boxw_mix.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

BIN
boxw_org.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B

205
graphics.s Normal file
View File

@ -0,0 +1,205 @@
;
; graphics.s
;
; Created by Quinn Dunki on 9/10/16
; Copyright (c) 2015 One Girl, One Laptop Productions. All rights reserved.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; EnableHires
; Trashes A
;
EnableHires:
lda TEXT
lda HIRES1
lda HIRES2
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SaveBackground
; PARAM0: X pos
; PARAM1: Y pos
; PARAM2: Storage area (LSB)
; PARAM3: Storage area (MSB)
;
; Assumes 6-byte-wide, 8px-high sprites
;
SaveBackground:
SAVE_AXY
ldy #0
lda #0
pha
saveBackground_loop:
clc
pla
pha
adc PARAM1 ; Calculate Y line
tax
lda HGRROWS_H,x ; Compute hires row
sta saveBackground_smc0+2
sta saveBackground_smc1+2
sta saveBackground_smc2+2
sta saveBackground_smc3+2
lda HGRROWS_L,x
sta saveBackground_smc0+1
sta saveBackground_smc1+1
sta saveBackground_smc2+1
sta saveBackground_smc3+1
ldx PARAM0 ; Compute hires column
lda DIV7_2,x
tax
saveBackground_smc0:
lda $2000,x
sta (PARAM2),y
iny
inx
saveBackground_smc1:
lda $2000,x
sta (PARAM2),y
iny
inx
saveBackground_smc2:
lda $2000,x
sta (PARAM2),y
iny
inx
saveBackground_smc3:
lda $2000,x
sta (PARAM2),y
iny
pla
inc
pha
cpy #48
bne saveBackground_loop
pla
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; RestoreBackground
; PARAM0: X pos
; PARAM1: Y pos
; PARAM2: Storage area (LSB)
; PARAM3: Storage area (MSB)
;
; Assumes 4-byte-wide, 8px-high sprites
;
RestoreBackground:
SAVE_AXY
ldy #0
lda #0
pha
restoreBackground_loop:
clc
pla
pha
adc PARAM1 ; Calculate Y line
tax
lda HGRROWS_H,x ; Compute hires row
sta restoreBackground_smc0+2
sta restoreBackground_smc1+2
sta restoreBackground_smc2+2
sta restoreBackground_smc3+2
lda HGRROWS_L,x
sta restoreBackground_smc0+1
sta restoreBackground_smc1+1
sta restoreBackground_smc2+1
sta restoreBackground_smc3+1
ldx PARAM0 ; Compute hires column
lda DIV7_2,x
tax
lda (PARAM2),y
restoreBackground_smc0:
sta $2000,x
iny
inx
lda (PARAM2),y
restoreBackground_smc1:
sta $2000,x
iny
inx
lda (PARAM2),y
restoreBackground_smc2:
sta $2000,x
iny
inx
lda (PARAM2),y
restoreBackground_smc3:
sta $2000,x
iny
pla
inc
pha
cpy #48
bne restoreBackground_loop
pla
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; LinearFill
; A: Byte value to fill
; Trashes all registers
;
LinearFill:
ldx #0
linearFill_outer:
pha
lda HGRROWS_H,x
sta linearFill_inner+2
lda HGRROWS_L,x
sta linearFill_inner+1
pla
ldy #39
linearFill_inner:
sta $2000,y
dey
bpl linearFill_inner
inx
cpx #192
bne linearFill_outer
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; VenetianFill
; A: Byte value to fill
; Trashes all registers
;
VenetianFill:
ldx #$3f
venetianFill_outer:
stx venetianFill_inner+2
ldy #$00
venetianFill_inner:
sta $2000,y ; Upper byte of address is self-modified
iny
bne venetianFill_inner
dex
cpx #$1f
bne venetianFill_outer
rts

Binary file not shown.

View File

@ -1,5 +1,5 @@
; ;
; hgrtest.s ; hisprite.s
; ;
; Created by Quinn Dunki on 7/19/16 ; Created by Quinn Dunki on 7/19/16
; Copyright (c) 2015 One Girl, One Laptop Productions. All rights reserved. ; Copyright (c) 2015 One Girl, One Laptop Productions. All rights reserved.
@ -65,98 +65,106 @@ main:
jsr EnableHires jsr EnableHires
lda #$00 lda #$00
jsr LinearFill jsr VenetianFill
ldx #0 ldx #0
;;;;
stz PARAM0
stz PARAM1
jsr BOXW_MAG
lda #10
sta PARAM1
jsr BOXW_MIX
lda #20
sta PARAM1
jsr BOXW_ORG
rts
;;;;
loop: loop:
txa txa
asl
asl
sta PARAM0 sta PARAM0
lda #0 lda #0
sta PARAM1 sta PARAM1
jsr BOX_MAG
lda #88 lda #<bgBuffer
sta PARAM1 sta PARAM2
jsr BOX_GRN lda #>bgBuffer
sta PARAM3
jsr SaveBackground
lda #96 jsr BOXW_MAG
sta PARAM1 lda #$80
jsr BOX_ORG jsr ROMWAIT
lda #184 jsr RestoreBackground
sta PARAM1
jsr BOX_BLU
inx inx
cpx #35 cpx #133
bne loop ; bne loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; EnableHires
; Trashes A
;
EnableHires:
lda TEXT
lda HIRES1
lda HIRES2
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; LinearFill
; A: Byte value to fill
; Trashes all registers
;
LinearFill:
ldx #0
linearFill_outer:
pha
lda HGRROWS_H,x
sta linearFill_inner+2
lda HGRROWS_L,x
sta linearFill_inner+1
pla
ldy #39
linearFill_inner:
sta $2000,y
dey
bpl linearFill_inner
inx
cpx #192
bne linearFill_outer
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; VenetianFill
; A: Byte value to fill
; Trashes all registers
;
VenetianFill:
ldx #$3f
venetianFill_outer:
stx venetianFill_inner+2
ldy #$00
venetianFill_inner:
sta $2000,y ; Upper byte of address is self-modified
iny
bne venetianFill_inner
dex
cpx #$1f
bne venetianFill_outer
rts rts
bgBuffer:
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.byte 0
.include "graphics.s"
.include "hgrtableX.s" .include "hgrtableX.s"
.include "hgrtableY.s" .include "hgrtableY.s"
.include "spritegen0.s" .include "spritegen0.s"
.include "spritegen1.s" .include "spritegen1.s"
.include "spritegen2.s" .include "spritegen2.s"
.include "spritegen3.s" .include "spritegen3.s"
.include "spritegen4.s"
; Suppress some linker warnings - Must be the last thing in the file ; Suppress some linker warnings - Must be the last thing in the file
.SEGMENT "ZPSAVE" .SEGMENT "ZPSAVE"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1408
spritegen4.s Normal file

File diff suppressed because it is too large Load Diff