-
Notifications
You must be signed in to change notification settings - Fork 4
/
IntelHex.65s
165 lines (146 loc) · 8.24 KB
/
IntelHex.65s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
; LIBRARY FILE
; version 2.20
; two pass symbolic assembler, dissembler and tracer
; REGB bits 0-3 are connected to LED's
; tested in Michael Kowalski 6502 Simulator - using 65C02 Code
; Programmed by Joe DiMeglio
; https://github.com/jdimeglio/6502-Monitor
; bug fixes
;----------------------------------------------------------------------------------------
;Intel HEX loader
;----------------------------------------------------------------------------------------
CHECKSUM = LENG
CMD_INTELHEX SEI ;stop Interrupts
CLD ;binary mode additons
STZ EXP_SAVE ;temp
STZ DEC_SAVE ;Bytes count
STZ DEC_SAVE+1
STZ CHECKSUM ;checksum
LDA #CR
STA ACIA ;dont wait on port status
LDA #LF
STA ACIA ;dont wait on port status
BRA CONTINUE
NEXTRECORD JSR RDCHAR
CMP #CR
BNE PROTOCOLERROR
JSR RDCHAR ;CRLF and end of line (BUG there's a CHECKSUM)
CMP #LF
BNE PROTOCOLERROR
JSR RDCHAR
CMP #':'
BEQ CONTINUE
PROTOCOLERROR JSR WRCHAR
JSR STRING
.ASCII BELL,CR,LF," :PROTOCOL ERROR",CR,LF,EOS
JMP TERMINATE
CONTINUE JSR READ_DATA ;read rcord length with checksum add
STA COUNT ;load the amount of bytes to load into memory
JSR READ_DATA ;read hgh byte of memory location
STA SRCE+1 ;store hgh byte of memory location
JSR READ_DATA ;read low byte with checksum add
STA SRCE ;store
JSR READ_DATA ;get record type 01 = end
;CMP #$00 ;check if 00 if yes then type #00
BEQ .DATARECORD ;get the data frame
CMP #$01 ;is it type #01 ie: end of record
BNE .INVREC ;else invalid
JMP .END_RECORD
.INVREC JSR STRING
.ASCII BELL,CR,LF," :INVALID RECORD TYPE",CR,LF,EOS
JMP TERMINATE
.IF MYWYM
.LEDS .BYTE 1 ;quicker than a shift
.BYTE 2 ;knight rider lights
.BYTE 4
.BYTE 8
.BYTE 4
.BYTE 2
.ENDIF
.DATARECORD LDX COUNT ;DATASIZE
LDY #$00
.NEXT_BYTE JSR READ_DATA ;read two hex characters
STA (SRCE),y ;store in RAM
CMP (SRCE),y ;did it actually store
BNE .WRITEERROR ;no then error - probably no ram there
LDA #'#' ;write fast
STA ACIA ;dont wait on port status
INY ;next address
DEX ;next byte to recieve
;CPX #$00 ;all bytes recieved?
BNE .NEXT_BYTE ;no then get next record
JSR READ_DATA ;get checksum
.IF MYWYM
LDX EXP_SAVE ;which LED to turn on
LDY .LEDS,x
STY VIA
INX
STX EXP_SAVE
CPX #$06
BNE .LEDCNT
STZ EXP_SAVE ;leds shifting counter restart
.ENDiF
.LEDCNT JMP NEXTRECORD
.WRITEERROR JSR STRING
.ASCII BELL,CR,LF
.ASCII " :CANNOT WRITE AT ADDRESS $",EOS
LDA SRCE+1
JSR WR2HEX
LDA SRCE
JSR WR2HEX
JSR WRCRLF
BRA TERMINATE
.CHECKSUMERR JSR STRING
.ASCII BELL,LF,CR," :CHECK SUM ERROR",LF,CR,EOS
BRA TERMINATE
.END_RECORD JSR RD2HEX ;last two byes the CheckSUM
CLC
ADC CHECKSUM
BNE .CHECKSUMERR
JSR STRING
.ASCII BELL,CR,LF
.ASCII " :INTEL-HEX SUCCESSFUL",EOS
JSR STRING
.ASCII CR,LF
.ASCII " :TOTAL BYTES WRITTEN ",EOS
LDY DEC_SAVE
LDA DEC_SAVE+1
JSR WRDECI
.IF MYWYM
LDA #%00001001 ;set lights
STA REGB
.ENDIF
CLI
CLC
RTS ;return to caller
TERMINATE
.IF MYWYM
LDA #%00001111 ;LEDS arrange in the
STA REGB ;mode means an error
.ENDIF
SEC
CLI
RTS ;return to caller
;---------------------------------------------------------------------------------
READ_DATA JSR RD2HEX ;read two hex characters & checksum
;bcs ERRS
PHA
CLC
ADC CHECKSUM ;add to checksum
STA CHECKSUM
CLC
LDA DEC_SAVE
ADC #01
STA DEC_SAVE
LDA DEC_SAVE+1 ;add the carry
ADC #00
STA DEC_SAVE+1
PLA
RTS
;ERRS tsx ;remove the last RTS from stack
; inx
; inx
; txs
; jsr STRING ;read error from RS232
; .ASCIS BELL,CR,LF," :READ ERROR FROM ACIA",CR,LF,EOS
; BRA TERMINATE