A2osX/BMP2PIX.S.txt

368 lines
6.8 KiB
Plaintext
Raw Normal View History

NEW
2018-11-17 17:17:13 +00:00
PREFIX
2017-12-22 21:24:30 +00:00
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
2018-07-23 15:28:42 +00:00
.TF ROOT/BMP2PIX
*--------------------------------------
2018-07-23 15:28:42 +00:00
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/GUI.I
.INB INC/LIBGUI.I
*--------------------------------------
ZPPTR1 .EQ ZPBIN
ZPInputBufPtr .EQ ZPBIN+2
ZPInputBufLen .EQ ZPBIN+4
ZPInputDataPtr .EQ ZPBIN+6
ZPBMPRowBytes .EQ ZPBIN+8
ZPPIXRowBytes .EQ ZPBIN+10
ZPBufPtr .EQ ZPBIN+12
ZPLineCount .EQ ZPBIN+14
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #64 SS
.DA #16 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.FILE.OK .DA MSG.FILE.OK
L.MSG.HEADER.OK .DA MSG.HEADER.OK
L.MSG.HEADER.KO .DA MSG.HEADER.KO
L.MSG.DONE .DA MSG.DONE
.DA 0
*--------------------------------------
CS.INIT
.1 >INC.G ArgCount
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
bcs .7
>STYA ZPPtr1
lda (ZPPtr1)
cmp #'-'
bne .4
ldy #1
lda (ZPPtr1),y
ldx OptionList
.2 cmp OptionList,x
beq .3
dex
bne .2
.99 >LDYA L.MSG.USAGE
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2018-10-21 20:54:07 +00:00
lda #E.SYN
sec
rts
.3 ldy OptionVars-1,x
lda #$80
sta (pData),y
bra .1
.4 >LDA.G hInputBuf
bne .5
jsr CS.INIT.OPENINPUT
bcc .1 scan for any other args
rts
.5 >LDA.G hOutputFile
bne .99
jsr CS.INIT.CREATEOUTPUT
bcc .1 scan for any other args
rts
.7 >LDA.G hOutputFile
beq .99
>LDYAI 256
2018-07-20 11:51:08 +00:00
>SYSCALL getmem
bcs CS.INIT.RTS
>STYA ZPBufPtr
txa
>STA.G hBuf
.8 clc
CS.INIT.RTS rts
*--------------------------------------
CS.INIT.OPENINPUT
>PUSHWI 0 Aux type
>PUSHBI 0 Type
2018-10-02 15:52:30 +00:00
>PUSHBI O.RDONLY
2018-07-25 15:26:14 +00:00
>LDYA ZPPtr1
>SYSCALL LoadFile
bcs CS.INIT.RTS
>STYA ZPInputBufLen
>PUSHYA
txa
>STA.G hInputBuf
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPInputBufPtr
>LDYA L.MSG.FILE.OK
2018-06-21 15:12:10 +00:00
>SYSCALL printf
lda (ZPInputBufPtr)
cmp #'B'
bne .99
ldy #1
lda (ZPInputBufPtr),y
cmp #'M'
bne .99
ldy #$1C BBP LO
lda (ZPInputBufPtr),y
cmp #1
bne .99
iny BBP HI
lda (ZPInputBufPtr),y
bne .99
ldy #$16 H LO
lda (ZPInputBufPtr),y
>STA.G PIX.Header+S.BM.H
pha
eor #$ff
sta ZPLineCount
ldy #$17 H HI
lda (ZPInputBufPtr),y
>STA.G PIX.Header+S.BM.H+1
>PUSHA
eor #$ff
sta ZPLineCount+1
pla
>PUSHA
ldy #$12 W LO
lda (ZPInputBufPtr),y
>STA.G PIX.Header+S.BM.W
pha
ldy #$13 W HI
lda (ZPInputBufPtr),y
>STA.G PIX.Header+S.BM.W+1
>PUSHA
pla
>PUSHA
>LDYA L.MSG.HEADER.OK
2018-06-21 15:12:10 +00:00
>SYSCALL printf
clc
rts
.99 >LDYA L.MSG.HEADER.KO
2018-06-21 15:12:10 +00:00
>SYSCALL printf
2018-10-21 20:54:07 +00:00
lda #E.IBIN
sec
rts
*--------------------------------------
CS.INIT.CREATEOUTPUT
>PUSHWI 0 Aux type
>PUSHBI $CB PIX Type
2018-10-02 15:52:30 +00:00
>PUSHBI O.WRONLY+O.CREATE
2018-07-25 15:26:14 +00:00
>LDYA ZPPtr1
>SYSCALL FOpen
bcs .9
>STA.G hOutputFile
.9 rts
*--------------------------------------
CS.RUN lda #S.BM.F.BBP1
>STA.G PIX.Header+S.BM.F
>LDA.G PIX.Header+S.BM.W
sta ZPBMPRowBytes
sta ZPPIXRowBytes
iny
lda (pData),y
sta ZPBMPRowBytes+1
sta ZPPIXRowBytes+1
lda ZPBMPRowBytes
and #%00011111
beq .1
lda ZPBMPRowBytes
and #%11100000
clc
adc #%00100000
bcc .1
inc ZPBMPRowBytes+1
.1 lsr ZPBMPRowBytes+1
ror
lsr ZPBMPRowBytes+1
ror
lsr ZPBMPRowBytes+1
ror
sta ZPBMPRowBytes
lda ZPPIXRowBytes
and #%00000111
beq .2
lda ZPPIXRowBytes
and #%11111000
clc
adc #%00001000
bcc .2
inc ZPPIXRowBytes+1
.2 lsr ZPPIXRowBytes+1
ror
lsr ZPPIXRowBytes+1
ror
lsr ZPPIXRowBytes+1
ror
sta ZPPIXRowBytes
>STA.G PIX.Header+S.BM.RowBytes
lda ZPInputBufPtr
clc
adc ZPInputBufLen
sta ZPInputDataPtr
lda ZPInputBufPtr+1
adc ZPInputBufLen+1
sta ZPInputDataPtr+1
>PUSHWI S.BM
2018-07-25 15:26:14 +00:00
>PUSHEA.G PIX.Header
>LDA.G hOutputFile
>SYSCALL FWrite
bcs CS.RUN.RTS
CS.RUN.LOOP inc ZPLineCount
bne .1
inc ZPLineCount+1
beq .8
.1 lda ZPInputDataPtr
sec
sbc ZPBMPRowBytes
sta ZPInputDataPtr
lda ZPInputDataPtr+1
sbc ZPBMPRowBytes+1
sta ZPInputDataPtr+1
>LDYA ZPBufPtr
>STYA ZPPTR1
ldy #0
.2 lda (ZPInputDataPtr),y
tax
lda TWIST,x
sta (ZPPTR1)
inc ZPPTR1
bne .3
inc ZPPTR1+1
.3 iny
cpy ZPPIXRowBytes
bne .2
>PUSHW ZPPIXRowBytes
2018-07-25 15:26:14 +00:00
>PUSHW ZPBufPtr
>LDA.G hOutputFile
>SYSCALL FWrite
bcs CS.RUN.RTS
bra CS.RUN.LOOP
.8 >LDYA L.MSG.DONE
2018-06-21 15:12:10 +00:00
>SYSCALL printf
lda #0
sec
CS.RUN.RTS rts
*--------------------------------------
CS.DOEVENT sec
rts
*--------------------------------------
CS.QUIT >LDA.G hBuf
beq .1
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.1 >LDA.G hOutputFile
beq .8
2018-07-20 11:51:08 +00:00
>SYSCALL fclose
.8 clc
rts
*--------------------------------------
CS.END
2017-12-12 07:27:36 +00:00
*--------------------------------------
2018-07-23 15:28:42 +00:00
.INB ROOT/X.TWIST.G
*--------------------------------------
OptionList >PSTR "Vv"
OptionVars .DA #bVerbose,#bVerbose
MSG.USAGE .AZ "Usage : BMP2PIX BMP-File \r\n -V : Verbose Mode\r\n"
MSG.FILE.OK .AZ "BMP Loaded, %D Bytes Read\r\n"
MSG.HEADER.OK .AZ "BMP Size : %D x %D pixels\r\n"
MSG.HEADER.KO .AZ "Invalid Input File Format\r\n"
MSG.DONE .AZ "All Done!!!\r\n"
2018-11-19 07:43:00 +00:00
*--------------------------------------
* LOWRES Patette : https://comp.sys.apple2.narkive.com/lTSrj2ZI/apple-ii-colour-rgb
*--------------------------------------
0 #000000
1 #e31e60
2 #604ebd
3 #ff44fd
4 #00a360
5 #9c9c9c
6 #14cffd
7 #d0c3ff
8 #607203
9 #ff6a3c
a #9c9c9c (yes it is the same as #5!)
b #ffa0d0
c #14f53c
d #d0dd8d
e #72ffd0
f #ffffff
*--------------------------------------
.DUMMY
.OR 0
DS.START
PIX.Header .BS S.BM
ArgCount .BS 1
hInputBuf .BS 1
hOutputFile .BS 1
bVerbose .BS 1
hBuf .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE /A2OSX.BUILD/ROOT/BMP2PIX.S
ASM