reading images form file
This commit is contained in:
@@ -16,3 +16,5 @@ oled
|
||||
```
|
||||
|
||||
Now paste your image hex data as generated by `oled-to-hex`.
|
||||
|
||||
You can also specify path to `OBM` file to load it from disk.
|
||||
|
||||
111
oled.mac
111
oled.mac
@@ -7,6 +7,15 @@ LF EQU 0Ah ; new line
|
||||
BDOS EQU 0005h ; BDOS entry point
|
||||
PSTR EQU 09h ; print string
|
||||
CRED EQU 01h ; read console
|
||||
FOPE EQU 0Fh ; file open
|
||||
FRED EQU 14h ; file read next record
|
||||
|
||||
FCB EQU 5Ch ; File Control Block
|
||||
FCBFNAME EQU FCB+01h ; FCB File Name
|
||||
FCBEX EQU FCB+0Ch ; FCB Excent Number
|
||||
FCBRC EQU FCB+0Fh ; FCB Record Count
|
||||
FCBCR EQU FCB+20h ; FCB Current Record
|
||||
FB EQU 80h ; File Buffer
|
||||
|
||||
OLED EQU 50h ; base addr of OLED card
|
||||
ORST EQU 04h ; reset command (H)
|
||||
@@ -22,7 +31,7 @@ OROWD EQU 0B3h ; select bottom row
|
||||
|
||||
OCOL0 EQU 04h ; left most column
|
||||
OSELC EQU 10h ; select column command
|
||||
OCOLL EQU 80h ; column count: 128 columns
|
||||
OCOL EQU 80h ; column count: 128 columns
|
||||
|
||||
; 128 columns from 4 to 131
|
||||
; 1Xh, 0Yh - XY = 04h to 83h
|
||||
@@ -30,28 +39,93 @@ OCOLL EQU 80h ; column count: 128 columns
|
||||
; MAIN
|
||||
CALL OINIT ; init OLED
|
||||
CALL OCLS ; clear screen
|
||||
CALL PROMPT ; print prompt
|
||||
|
||||
CALL OCSTART ; go to start
|
||||
CALL READLINE ; read row A
|
||||
CALL READLINE ; read row B
|
||||
CALL READLINE ; read row C
|
||||
CALL READLINE ; read row D
|
||||
|
||||
LD A,(FCBFNAME) ; load first char of file name
|
||||
CP ' ' ; check file name provided
|
||||
|
||||
JP NZ,MAIN1
|
||||
CALL PROMPTREAD ; read from prompt
|
||||
RET ; exit to CP/M
|
||||
|
||||
MAIN1:
|
||||
CALL FILEREAD ; read from file
|
||||
RET ; exit to CP/M
|
||||
|
||||
PROMPTREAD:
|
||||
LD DE,MSGPROMPT
|
||||
CALL PRINT ; print prompt
|
||||
|
||||
CALL READLINE ; read row A
|
||||
CALL READLINE ; read row B
|
||||
CALL READLINE ; read row C
|
||||
CALL READLINE ; read row D
|
||||
RET
|
||||
|
||||
FILEREAD:
|
||||
LD DE,MSGFILEREAD
|
||||
CALL PRINT ; print reading from file
|
||||
XOR A
|
||||
LD (FCBEX),A ; select 0'th extent
|
||||
LD (FCBRC),A ; clear
|
||||
LD (FCBCR),A ; select 0'th record
|
||||
LD C,FOPE ; open file
|
||||
LD DE,FCB ; use default FCB
|
||||
CALL BDOS
|
||||
CP 0FFh ; is error
|
||||
JP Z,FILEREAD1
|
||||
XOR A
|
||||
LD (FCBCR),A ; start from beginning
|
||||
CALL READRECORD ; read 128 byte record
|
||||
CALL READRECORD
|
||||
CALL READRECORD
|
||||
CALL READRECORD
|
||||
RET
|
||||
FILEREAD1:
|
||||
LD DE,MSGOPENERR
|
||||
CALL PRINT
|
||||
LD A,0FFh
|
||||
RET
|
||||
|
||||
READLINE:
|
||||
LD D,OCOLL ; number of columns
|
||||
LD D,OCOL ; number of columns
|
||||
READLINE1:
|
||||
PUSH DE
|
||||
CALL READHEX ; read hex input from console
|
||||
CALL ODATA ; write to OLED
|
||||
POP DE
|
||||
DEC D ; count donw columns
|
||||
DEC D ; count down columns
|
||||
JP NZ,READLINE1 ; next column
|
||||
RET
|
||||
|
||||
; reads block using default FCB
|
||||
; A=0 - OK
|
||||
; A=FFh - error
|
||||
READRECORD:
|
||||
LD C,FRED ; read file
|
||||
LD DE,FCB ; use default FCB
|
||||
CALL BDOS
|
||||
CP 0 ; check status code
|
||||
JP NZ,READRECORD1
|
||||
LD D,OCOL ; bytes to read
|
||||
LD HL,FB ; start of file buffer
|
||||
READRECORD0:
|
||||
LD A,(HL) ; load byte
|
||||
PUSH DE
|
||||
PUSH HL
|
||||
CALL ODATA ; send to oled
|
||||
POP HL
|
||||
POP DE
|
||||
INC HL ; next byte
|
||||
DEC D ; count columns down
|
||||
JP NZ,READRECORD0
|
||||
RET
|
||||
READRECORD1:
|
||||
LD DE,MSGREADERR
|
||||
CALL PRINT
|
||||
LD A,0FFh ; error
|
||||
RET
|
||||
|
||||
OINIT:
|
||||
CALL ORESET ; reset OLED
|
||||
LD HL,OINITSEQ ; commands to send
|
||||
@@ -61,7 +135,7 @@ OINITLOOP:
|
||||
RET Z ; marker reached
|
||||
CALL OCOMMAND ; send command from A
|
||||
INC HL ; next command
|
||||
JR OINITLOOP ; send next command
|
||||
JR OINITLOOP ; do next command
|
||||
|
||||
ORESET:
|
||||
LD C,OLED ; base I/O address
|
||||
@@ -98,7 +172,7 @@ OCSTART:
|
||||
OCLSROW:
|
||||
;XOR A ; display byte to write (0)
|
||||
LD A,0FFh ; turn on all pixels
|
||||
LD D,OCOLL ; count columns in D
|
||||
LD D,OCOL ; count columns in D
|
||||
OCLSROW1:
|
||||
CALL ODATA ; write A to displey
|
||||
DEC D ; next column
|
||||
@@ -139,7 +213,7 @@ ODATA:
|
||||
READ:
|
||||
LD C,CRED ; read from console
|
||||
CALL BDOS ; call CP/M
|
||||
RET ; A=CHAR
|
||||
RET ; A=char
|
||||
|
||||
; Reads 4 bit value (0-F)
|
||||
READNIB:
|
||||
@@ -169,15 +243,22 @@ READHEX:
|
||||
OR B ; OR B to A
|
||||
RET
|
||||
|
||||
PROMPT:
|
||||
; DE - address to $ terminated string
|
||||
PRINT:
|
||||
LD C,PSTR ; load function number
|
||||
LD DE,PROMPTMSG ; load string addr
|
||||
CALL BDOS ; call CP/M
|
||||
RET
|
||||
|
||||
PROMPTMSG:
|
||||
MSGPROMPT:
|
||||
DB 'OLED:>', CR, LF,'$' ; string terminated with $
|
||||
|
||||
MSGFILEREAD:
|
||||
DB 'Reading from file', CR, LF, '$'
|
||||
MSGOPENERR:
|
||||
DB 'Error opening file', CR, LF, '$'
|
||||
MSGREADERR:
|
||||
DB 'Error reading file', CR, LF, '$'
|
||||
|
||||
; Initialization sequence
|
||||
; 081h,080h - set contrast (080h full)
|
||||
; 020h,000h - set horizontal window wrapping
|
||||
|
||||
Reference in New Issue
Block a user