pushed updates

This commit is contained in:
Dennis Gunia
2024-06-24 09:21:16 +02:00
parent 488efa3907
commit d18e8e9e69
197 changed files with 316846 additions and 223785 deletions

View File

@@ -0,0 +1,89 @@
;----------------------------------------------------------------
; Terminal IN/OUT functions
;----------------------------------------------------------------
; prints out byte
; input:
; - a: byte to send
; modify:
; - af: destroy
bios_termout:
jp print_char
; reads in byte
; input:
; modify:
; - a: read byte
; - f: destroy
bios_termin:
jp read_char
; reads input status
; input:
; modify:
; - a: 0x00 if empty, 0xFF if byte is ready
; - f: destroy
bios_termsts:
jp read_in_sts
;----------------------------------------------------------------
; I2C IN/OUT functions
;----------------------------------------------------------------
; sends I2C buffer to device
; input:
; - HL contains buffer location
; - B defines amount of bytes to send
; - C contains device address
; modify:
; - af: destroy
bios_iic_send:
jp iic_send_buffer
; sends I2C buffer to device
; input:
; - HL contains buffer location
; - B defines amount of bytes to receive
; - C contains device address
; modify:
; - af: destroy
bios_iic_receive:
jp iic_receive_buffer
;----------------------------------------------------------------
; disk functions
;----------------------------------------------------------------
; selects drive 0-3
; input:
; - a contains drive number
; modify:
; - af: destroy
; - de: destroy
; - bc: destroy
; - hl: destroy
bios_disk_sel:
jp ideif_drv_sel
; gets pointer to selcetd drive information
; input:
; modify:
; - af: destroy
; - ix: pointer to start of entry
bios_disk_get:
jp ideif_get_drv_pointer
; reads from LBA address
; input:
; - a : sectro count
; - de: destination in memory
; - hl: pointer to sector value in memory (32 bit (lw))
; modify:
; - af: destroy
; - bc: destroy
; - de: destroy
; - hl: destroy
bios_disk_readlba:
jp read_lba_sector
;----------------------------------------------------------------
; filesystem functions
;----------------------------------------------------------------

View File

@@ -58,12 +58,11 @@ print_char:
print_str:
ld a, (hl)
or a
jr z,print_str_end
ret z
call print_char
inc hl
jr print_str
print_str_end:
ret
print_clear:
ld hl, [MSG_CLEAR]
@@ -118,6 +117,15 @@ read_char:
in a, (CS_SIO_A_D) ; read char if avail
ret ; return
read_in_sts:
out (CS_SIO_A_C), a ; select reg 0
in a, (CS_SIO_A_C) ; read reg 0
and 1 ; mask D0 (recieve char available)
ret z
ld a, 0xFF
ret
read_bcd;
call read_char
jp z, read_bcd

View File

@@ -46,6 +46,8 @@ MEM_FAT_EXEC_START:
dephase
;-------------------------------------
; Get FAT Root-Table position
;-------------------------------------
@@ -226,6 +228,7 @@ _fat_getfatsec_notroot:
;read FAT sector
ld hl,MEM_FAT_OF0_FATSEC ;read next sector
ld b,1
ld a,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
@@ -287,6 +290,7 @@ fat_readfilesec:
;call fat_print_dbg
ld hl,[MEM_FAT_OF0_DATSEC]
ld b,1
ld a,1
;LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector ;read sectore
ld hl,[MEM_FAT_OF0_DATSEC] ;increment pointer to next sector
@@ -342,6 +346,7 @@ fat_openfile_noprepare:
LD HL,MEM_IDE_POINTER ;read first sector
LD B,1
ld a,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
@@ -372,6 +377,7 @@ _fat_lfs_loop_compare_next_sector:
LD HL,MEM_IDE_POINTER ;read next sector
LD B,1
ld a,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector

View File

@@ -13,6 +13,7 @@ fat_print_directory:
LD (MEM_FAT_COUNT1),DE
LD HL,MEM_IDE_POINTER ;read first sector
LD B,1
ld a,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
@@ -112,7 +113,7 @@ _fat_print_directory_loop_next_sector: ; end fo sector. read next sector from d
LD HL,MEM_IDE_POINTER ;read next sector
LD B,1
ld a,1
LD DE, MEM_IDE_BUFFER ;where to store data?
call read_lba_sector
@@ -303,7 +304,8 @@ fat_exec:
call PRINTINLINE
db 10,13,"Loading ",0
ld hl,[var_input+6]
pop hl ;get and re-store pointer ot filename from and to stack
push hl
call print_str
call PRINTINLINE
db " to 0x",0

View File

@@ -37,6 +37,26 @@
IDE_REG_LBA2 .EQU 01101b ;High two bits of the cylinder number
IDE_REG_LBA3 .EQU 01110b ;Head and device select register
ide_wait_rdy macro
local wait
wait:
ld b, IDE_REG_CMDSTS
call ide_regread_8
rla
jr c, wait
endm
ide_wait_drq macro
local wait
wait:
ld b, IDE_REG_CMDSTS
call ide_regread_8
bit 0,a ;Error Bit set.
jp nz, ide_printerror
bit 3,a
jr z,wait
endm
;================================================================
; I/O access functions
@@ -53,7 +73,6 @@ ide_reset:
OUT (CS_PIA_CR), A ;Set Data direction to out
LD A, IDE_RST
OUT (CS_PIA_PC), A ;Reset IDE Device
NOP
XOR A
OUT (CS_PIA_PC), A ;end device reset
RET
@@ -80,11 +99,11 @@ ide_regwrite_8:
OUT (CS_PIA_PC), A ;Write Data to bit controll lines
OR IDE_WR ;Set Write bit
OUT (CS_PIA_PC), A ;Set write signal
NOP ;delay to wait for processing
;NOP ;delay to wait for processing
LD A, B ;Load register address
AND 00011111b ;Mask unused bits
OUT (CS_PIA_PC), A ;disable write signal
NOP
;NOP
XOR A ;clear register A
OUT (CS_PIA_PC), A ;clear controll lines
RET
@@ -106,15 +125,7 @@ ide_regread_8:
OUT (CS_PIA_PC), A ;Write Data to bit controll lines
OR IDE_RD ;Set Write bit
OUT (CS_PIA_PC), A ;Write Data to bit controll lines
NOP ;delay to wait for processing
PUSH AF
POP AF
PUSH AF
POP AF
PUSH AF
POP AF
PUSH AF
POP AF
NOP
IN A,(CS_PIA_PA) ;read data from ide device to b (because a is used later)
PUSH AF
XOR A ;clear register A
@@ -122,80 +133,42 @@ ide_regread_8:
POP AF ;put data in accumulator
RET
;------------------------------------------------------------------------------
; ide_readsector_256
; ide_readsector_512_fast
;
; Reads IDE Data
; Reads IDE Data until no more data is available (multiple sectors)
; HL contains destination address
; A returns 0 on success, 1 on error
;------------------------------------------------------------------------------
ide_readsector_256:
LD C,0 ;Setup counter for 256 words
ide_readsector_256_waitloop:
LD B, IDE_REG_CMDSTS
CALL ide_regread_8
BIT 0,a ;Error Bit set.
JP NZ, ide_printerror
BIT 3,a ;DRQ Bit set. If set, disk has data
JR Z, ide_readsector_256_waitloop ;If not set, wait
LD A, 10010010b ;CommandByte-A, Mode 0, PA IN, PC Out, PB IN
OUT (CS_PIA_CR), A ;Set Data direction to IN
LD A, IDE_REG_DATA ;CS0 and A=0 -> I/O register
OUT (CS_PIA_PC), A ;set register
OR IDE_RD ;Set Read bit
OUT (CS_PIA_PC), A ;Write Read to bit controll lines
NOP
;NOP
;NOP
IN A,(CS_PIA_PB) ;Load 16-Bit data to buffer
LD (HL), A
INC HL
IN A,(CS_PIA_PA)
LD (HL), A
INC HL
DEC C
RET Z
JR ide_readsector_256_waitloop
ide_readsector_512_inv:
LD C,0 ;Setup counter for 256 words
LD DE, 4096 ;Timeout counter
ide_readsector_512_inv_waitloop:
DEC DE
LD A,D
OR E
JP Z, ide_readsector_timeout
;timeout checked. continue
LD B, IDE_REG_CMDSTS
CALL ide_regread_8
BIT 0,a ;Error Bit set.
JP NZ, ide_printerror
BIT 3,a ;DRQ Bit set. If set, disk has data
JR Z, ide_readsector_512_inv_waitloop ;If not set, wait
LD DE, 2048 ;Timeout counter
LD A, 10010010b ;CommandByte-A, Mode 0, PA IN, PC Out, PB IN
OUT (CS_PIA_CR), A ;Set Data direction to IN
LD A, IDE_REG_DATA ;CS0 and A=0 -> I/O register
OUT (CS_PIA_PC), A ;set register
OR IDE_RD ;Set Read bit
OUT (CS_PIA_PC), A ;Write Read to bit controll lines
;NOP
;NOP
NOP
IN A,(CS_PIA_PA) ;Load 16-Bit data to buffer
LD (HL), A
INC HL
IN A,(CS_PIA_PB)
LD (HL), A
INC HL
DEC C
RET Z
JR ide_readsector_512_inv_waitloop
ide_readsector_512_fast:
ld b, IDE_REG_CMDSTS ;check status
call ide_regread_8
bit 0,a ;Error Bit set
jp nz, ide_printerror ;then abort
bit 3,a ;wait for drq
jr z,ide_readsector_512_fast
ld b,0 ;256x
ld a, 10010010b ;CommandByte-A, Mode 0, PA IN, PC Out, PB IN
out (CS_PIA_CR), a ;Set Data direction to IN
_ide_readsector_512_floop:
ld a, IDE_REG_DATA ;CS0 and A=0 -> I/O register
out (CS_PIA_PC), a ;set register
or IDE_RD ;Set Read bit
out (CS_PIA_PC), a ;Write Read to bit controll lines
in a,(CS_PIA_PA) ;load first byte
ld (hl), a
inc hl
in a,(CS_PIA_PB) ;load second byte
ld (hl), a
inc hl
djnz _ide_readsector_512_floop ;loop 256 times (256words = 512 bytes)
ld b, IDE_REG_CMDSTS;check drive status
call ide_regread_8 ;
and 10001001b ;busy, DRQ, or error?
ret z ;no more data or errors -> exit
bit 3,a ;test if more data available
jr nz,ide_readsector_512_fast ;if true, repeat read function
jp ide_printerror ;else exit function
ide_readsector_timeout:
LD HL, [str_error_time]
@@ -208,9 +181,6 @@ ide_readsector_timeout:
CALL print_char
RET
;------------------------------------------------------------------------------
; ide_writesector_256
;
@@ -249,7 +219,7 @@ ide_printerror:
CALL print_char
LD A,13
CALL print_char
LD A,1
RET
str_error_start:

View File

@@ -240,7 +240,7 @@ ideif_init_drive:
;ld e,a
call ide_reset
ld bc, 0x5FFF ;preload timeout counter
ld de, 0xAFFF ;preload timeout counter
_ideif_init_drive_loop:
ld b, IDE_REG_CMDSTS
call ide_regread_8 ;read drive status register
@@ -265,36 +265,50 @@ _ideif_init_drive_found:
ld a, IDE_CMD_IDENT
call ide_regwrite_8 ;Write command to drive
ld hl, MEM_IDE_BUFFER ;set read/write buffer start address
call ide_readsector_256 ;read 256 words from device
call ide_readsector_512_fast ;read 256 words from device
ld hl,MEM_IDE_BUFFER + 54 ;print device serial
ld a,(ix+12) ;load str pointer into de
ld e,a
ld a,(ix+13)
ld d,a
ld bc,40 ;copy 40 char
ldir
ld b,20
_ideif_init_drive_charloop:
ld a,(hl) ;load data from HL (buffer)
inc hl
ex af,af'
ld a,(hl)
inc hl
ld (de),a
inc de
ex af,af'
ld (de),a
inc de
djnz _ideif_init_drive_charloop
;get partition table
;read bootsector
ide_wait_rdy
ld a,1 ;read 1 sector
ld B,IDE_REG_SECTOR
call ide_regwrite_8
ld a,1 ;read sector 0
ld b,IDE_REG_SSECTOR
ld a,0 ;read sector 0
ld b,IDE_REG_LBA0
call ide_regwrite_8
ld a,0 ;read cylinder 0
ld b,IDE_REG_LCYL
ld b,IDE_REG_LBA1
call ide_regwrite_8
ld a,0
ld b,IDE_REG_HCYL
ld b,IDE_REG_LBA2
call ide_regwrite_8
ld a,10100000b ;read head 0
ld b,IDE_REG_HEAD
ld a,11100000b ;read head 0
ld b,IDE_REG_LBA3
call ide_regwrite_8
ld a,IDE_CMD_READSEC ;send read command
ld b,IDE_REG_CMDSTS
call ide_regwrite_8
ld hl, MEM_IDE_BUFFER ;set read/write buffer start address
call ide_readsector_512_inv ;read 256 words from device
call ide_readsector_512_fast ;read 256 words from device
;prepare partitions
ld b,4 ;Partition table length
ld c,0 ;Partition ID counter
@@ -393,6 +407,9 @@ ideif_init_all:
; A contains sector count
;------------------------------------------------------------------------------
read_lba_sector:
push af
ide_wait_rdy
pop af
LD B,IDE_REG_SECTOR ;amount of sectores
CALL ide_regwrite_8
@@ -417,10 +434,10 @@ read_lba_sector:
LD A,IDE_CMD_READSEC ;send read command
LD B,IDE_REG_CMDSTS
CALL ide_regwrite_8
;LD HL,MEM_IDE_BUFFER ;set read/write buffer start address
EX DE,HL ;transfer destination in DE to HL
call ide_readsector_512_inv ;read 256 words from device
ret
jp ide_readsector_512_fast ;read 256 words from device
;------------------------------------------------------------------------------
; ideif_drv_sel

View File

@@ -90,6 +90,9 @@ iic_receive_buffer_err:
;Reset PIO configuration
iic_init:
;SCL HIGH, SDA HIGH
LD A,0x03
OUT (CS_PIO_AD), A
;Set port to controll mode (MODE3)
LD A,0xCF
OUT (CS_PIO_AC), A
@@ -100,6 +103,9 @@ iic_init:
; send start bit
iic_send_sbit:
;SCL HIGH, SDA HIGH
LD A,0x03
OUT (CS_PIO_AD), A
;Set port to controll mode (MODE3)
LD A,0xCF
OUT (CS_PIO_AC), A

View File

@@ -0,0 +1,63 @@
;-------------------------------------
; BIOS Routines entry points
; Do not move in memory!!!!
;-------------------------------------
.org 0x0050
B_BEEP:
jp beep
B_IICSEND:
jp iic_send_buffer
B_IICRECV:
jp iic_receive_buffer
B_PRINTCHAR:
jp print_char
B_PRINTSTR:
jp print_str
B_PRINTINLINE:
jp PRINTINLINE
B_PRINTAHEX:
jp print_a_hex
B_PRINTLN:
jp print_newLine
B_READCHAR:
jp read_char
B_KEYREAD:
ret ;placeholder -> not implemented
db 0x00, 0x00
B_KEYREADASCII:
ret ;placeholder -> not implemented
db 0x00, 0x00
B_KEYSEND:
ret ;placeholder -> not implemented
db 0x00, 0x00
B_DSKSEL:
jp ideif_drv_sel
B_FATOPEN:
jp fat_openfile
B_FATREAD:
jp fat_readfilesec
B_FATCD:
jp fat_cd_single
B_FATCREATE:
ret ;placeholder -> not implemented
db 0x00, 0x00
B_FATWRITE:
ret ;placeholder -> not implemented
db 0x00, 0x00