reorganize everything
This commit is contained in:
18
OperatingSystem/.unused/software/include/bcd.s
Normal file
18
OperatingSystem/.unused/software/include/bcd.s
Normal file
@@ -0,0 +1,18 @@
|
||||
; prints A as BCD
|
||||
|
||||
print_bcd_byte_3:
|
||||
PUSH DE
|
||||
PUSH BC
|
||||
PUSH HL
|
||||
PUSH IX
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print_bcd_done:
|
||||
POP IX
|
||||
POP HL
|
||||
POP BC
|
||||
POP DE
|
||||
RET
|
||||
1
OperatingSystem/.unused/software/include/extern_symbols.s
Symbolic link
1
OperatingSystem/.unused/software/include/extern_symbols.s
Symbolic link
@@ -0,0 +1 @@
|
||||
../../monitor_v2/zout/symbols.s
|
||||
608
OperatingSystem/.unused/software/include/fat16.s
Normal file
608
OperatingSystem/.unused/software/include/fat16.s
Normal file
@@ -0,0 +1,608 @@
|
||||
; VARS
|
||||
|
||||
phase MEM_IDE_FSBUFFER
|
||||
MEM_FAT_RESERVED: ; Reserved sectors (2byte)
|
||||
defs 2
|
||||
MEM_FAT_AMOUNT: ; Amount of FATs (1byte)
|
||||
defs 1
|
||||
MEM_FAT_SECTORS: ; Length of FAT (2byte)
|
||||
defs 2
|
||||
MEM_FAT_CLUSTERLEN: ; Length of Cluster (1byte)
|
||||
defs 1
|
||||
MEM_FAT_COUNT1: ; Counter Var for reading FAT (2byte)
|
||||
defs 1
|
||||
MEM_FAT_TMPPOINTER: ; Temporary working pointer
|
||||
defs 4
|
||||
MEM_FAT_DATASTART: ; Start of data area
|
||||
defs 4
|
||||
MEM_FAT_ROOTSTART: ; Start of Root directory
|
||||
defs 4
|
||||
MEM_FAT_FILEREMAIN: ; Remaining sectors in file
|
||||
defs 4
|
||||
MEM_FAT_DIRSEC: ; Sectors per directory
|
||||
defs 2
|
||||
MEM_FAT_TMPFNAME: ; Temporary filename
|
||||
defs 16
|
||||
MEM_FAT_CURDIR: ; Current Directory
|
||||
defs 80
|
||||
MEM_FAT_OF0_ATTRIBUTE: ;Current file attribute
|
||||
defw 0
|
||||
MEM_FAT_OF0_CCLUST: ;Current cluster of file
|
||||
defw 0
|
||||
MEM_FAT_OF0_FATSEC: ;Current sector in FAT
|
||||
defs 4
|
||||
MEM_FAT_OF0_DATSEC: ;Current sector in Data
|
||||
defs 4
|
||||
MEM_FAT_OF0_DATREM: ;Remaining bytes in Data
|
||||
defs 4
|
||||
MEM_FAT_CURRDIR: ;Current directory
|
||||
defs 4
|
||||
MEM_FAT_EXEC_CURR:
|
||||
defw 0
|
||||
MEM_FAT_EXEC_COUNT:
|
||||
defw 0
|
||||
MEM_FAT_EXEC_START:
|
||||
defw 0
|
||||
|
||||
dephase
|
||||
|
||||
;-------------------------------------
|
||||
; Get FAT Root-Table position
|
||||
;-------------------------------------
|
||||
fat_get_root_table:
|
||||
call fat_reset_pointer ;reset fat pointer
|
||||
|
||||
; Load first sector on active partition
|
||||
LD HL, MEM_IDE_POINTER ; pointer to LBA address
|
||||
LD A,1 ;read 1 sector
|
||||
LD DE, MEM_IDE_BUFFER ;where to store data?
|
||||
call read_lba_sector
|
||||
|
||||
; check for valid Boot sector
|
||||
ld a,(MEM_IDE_BUFFER)
|
||||
cp 0xEB ;first byte should be 0xEB
|
||||
jp nz, _fat_get_root_table_invalid
|
||||
|
||||
; Read and store FS Properties
|
||||
LD IX,MEM_IDE_BUFFER
|
||||
LD A,(IX+0x0D)
|
||||
LD (MEM_FAT_CLUSTERLEN),A
|
||||
LD A,(IX+0x0E)
|
||||
LD (MEM_FAT_RESERVED),A
|
||||
LD A,(IX+0x0F)
|
||||
LD (MEM_FAT_RESERVED+1),A
|
||||
LD A,(IX+0x10)
|
||||
LD (MEM_FAT_AMOUNT),A
|
||||
LD A,(IX+0x16)
|
||||
LD (MEM_FAT_SECTORS),A
|
||||
LD A,(IX+0x17)
|
||||
LD (MEM_FAT_SECTORS+1),A
|
||||
|
||||
;Get Data Start Sector
|
||||
;calculate fat length
|
||||
ld bc,(MEM_FAT_SECTORS)
|
||||
ld a,(MEM_FAT_AMOUNT) ;add fat to cluster number
|
||||
ld d,0
|
||||
ld e,a
|
||||
call _fat_math_mul32
|
||||
; BCHL contains result -> store to PTR.MEM_FAT_ROOTSTART
|
||||
ld (MEM_FAT_ROOTSTART+0),hl
|
||||
ld (MEM_FAT_ROOTSTART+2),bc
|
||||
|
||||
;add offset (reserved sectors)
|
||||
ld hl,(MEM_IDE_BUFFER +0x0E) ; load sectors into hl
|
||||
ld (MEM_FAT_TMPPOINTER), hl
|
||||
xor a
|
||||
ld (MEM_FAT_TMPPOINTER+2),a
|
||||
ld (MEM_FAT_TMPPOINTER+3),a
|
||||
|
||||
ld bc,[MEM_FAT_ROOTSTART]
|
||||
ld de,[MEM_FAT_TMPPOINTER]
|
||||
call _fat_math_add32 ;MEM_FAT_ROOTSTART now contains the first sector
|
||||
;of the Root directory
|
||||
|
||||
;add offset (partition location)
|
||||
call ideif_get_drv_pointer
|
||||
inc ix
|
||||
inc ix
|
||||
push ix
|
||||
pop de ;copy poiter to hl
|
||||
ld bc,[MEM_FAT_ROOTSTART]
|
||||
call _fat_math_add32 ;MEM_FAT_OF0_DATSEC now contains the first sector
|
||||
;of the cluster
|
||||
;copy value from MEM_FAT_ROOTSTART to MEM_IDE_POINTER
|
||||
ld hl,MEM_FAT_ROOTSTART
|
||||
ld de,MEM_IDE_POINTER
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
|
||||
;copy value from MEM_FAT_ROOTSTART to MEM_IDE_POINTER
|
||||
ld hl,MEM_FAT_ROOTSTART
|
||||
ld de,MEM_FAT_DATASTART
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
|
||||
ld hl,MEM_FAT_ROOTSTART
|
||||
ld de,MEM_FAT_CURRDIR
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
|
||||
;add offset to data area
|
||||
;multiply cluster by length of cluster
|
||||
|
||||
;calculate sectors for root dir
|
||||
ld hl,(MEM_IDE_BUFFER+0x11) ;load Maximum root directory entries
|
||||
ld a,h
|
||||
ld l,a
|
||||
xor a ;set a 0, clear carry flag
|
||||
ld h,a ;shift right by 8 bit = /512
|
||||
|
||||
;last step: multiply by 16
|
||||
ex de,hl
|
||||
ld bc,16
|
||||
call _fat_math_mul32
|
||||
; BCHL contains result -> store to PTR.MEM_FAT_TMPPOINTER
|
||||
ld (MEM_FAT_TMPPOINTER+0),hl
|
||||
ld (MEM_FAT_TMPPOINTER+2),bc
|
||||
|
||||
ld (MEM_FAT_DIRSEC),hl
|
||||
; add offset to MEM_FAT_DATASTART
|
||||
ld de,[MEM_FAT_TMPPOINTER]
|
||||
ld bc,[MEM_FAT_DATASTART]
|
||||
call _fat_math_add32 ;MEM_FAT_DATASTART now contains the correct sector
|
||||
;at teh beginnig of the data area
|
||||
|
||||
|
||||
;done all FS vars populated
|
||||
|
||||
;navigate to root directory
|
||||
ld a,'\'
|
||||
ld(MEM_FAT_CURDIR),a
|
||||
xor a
|
||||
ld(MEM_FAT_CURDIR+1),a
|
||||
|
||||
ret
|
||||
|
||||
_fat_get_root_table_invalid:
|
||||
call PRINTINLINE
|
||||
db 10,13,"Cannot find boot sector.",10,13,0
|
||||
call ideif_get_drv_pointer
|
||||
ld (ix+0),0x02
|
||||
ret
|
||||
|
||||
;-------------------------------------
|
||||
; Print current fat directory of MEM_FAT_CURRDIR
|
||||
;-------------------------------------
|
||||
fat_print_directory:
|
||||
ld hl,MEM_FAT_CURRDIR
|
||||
ld de,MEM_IDE_POINTER
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
|
||||
LD DE,(MEM_FAT_SECTORS)
|
||||
LD (MEM_FAT_COUNT1),DE
|
||||
LD HL,MEM_IDE_POINTER ;read first sector
|
||||
LD B,1
|
||||
LD DE, MEM_IDE_BUFFER ;where to store data?
|
||||
call read_lba_sector
|
||||
|
||||
call PRINTINLINE
|
||||
db 10,13," Filename Cluster Size",10,13,0
|
||||
|
||||
LD HL, MEM_IDE_BUFFER ;set buffer start
|
||||
LD C,16 ;set entries counter
|
||||
|
||||
_fat_print_directory_loop: ;loop over each entry (32byte)
|
||||
LD A,(HL) ; check first byte
|
||||
PUSH HL ;backup start of entry
|
||||
POP IX
|
||||
PUSH HL
|
||||
;ignore unwanted entries
|
||||
CP 0x41 ;skip invisible
|
||||
JP Z, _fat_print_directory_loop_next
|
||||
CP 0xE5 ;skip deleted
|
||||
JP Z, _fat_print_directory_loop_next
|
||||
CP 0x00 ;reached end
|
||||
JP Z, _fat_print_directory_loop_break
|
||||
|
||||
;check file attribute
|
||||
ld a,(IX+0x0B)
|
||||
cp 0x10 ;if subdirectors
|
||||
jp z, _fat_print_directory_dir ;print dir
|
||||
;else print file
|
||||
_fat_print_directory_loop_file
|
||||
;print filename
|
||||
ld a,' '
|
||||
call print_char
|
||||
ld a,' '
|
||||
call print_char
|
||||
LD B,8
|
||||
call print_str_fixed
|
||||
ld A,'.'
|
||||
call print_char
|
||||
LD B,3
|
||||
call print_str_fixed
|
||||
|
||||
call PRINTINLINE
|
||||
db " 0x",0
|
||||
;first cluster number
|
||||
ld a,(ix+0x1B)
|
||||
call print_a_hex
|
||||
ld a,(ix+0x1A)
|
||||
call print_a_hex
|
||||
call PRINTINLINE
|
||||
db " 0x",0
|
||||
ld a,(ix+0x1F)
|
||||
call print_a_hex
|
||||
ld a,(ix+0x1E)
|
||||
call print_a_hex
|
||||
ld a,(ix+0x1D)
|
||||
call print_a_hex
|
||||
ld a,(ix+0x1C)
|
||||
call print_a_hex
|
||||
|
||||
LD A,10 ;New line
|
||||
CALL print_char
|
||||
LD A,13
|
||||
CALL print_char
|
||||
jr _fat_print_directory_loop_next
|
||||
_fat_print_directory_dir
|
||||
ld a,'D'
|
||||
call print_char
|
||||
ld a,' '
|
||||
call print_char
|
||||
LD B,8
|
||||
call print_str_fixed
|
||||
call PRINTINLINE
|
||||
db " 0x",0
|
||||
;first cluster number
|
||||
ld a,(ix+0x1B)
|
||||
call print_a_hex
|
||||
ld a,(ix+0x1A)
|
||||
call print_a_hex
|
||||
|
||||
LD A,10 ;New line
|
||||
CALL print_char
|
||||
LD A,13
|
||||
CALL print_char
|
||||
jr _fat_print_directory_loop_next
|
||||
|
||||
_fat_print_directory_loop_next: ; read next entry
|
||||
DEC C ;next sector after 32 entries
|
||||
JR Z,_fat_print_directory_loop_next_sector
|
||||
POP HL ;restore start
|
||||
LD DE, 32 ;length of entry
|
||||
ADD HL,DE ;increment
|
||||
JP _fat_print_directory_loop
|
||||
|
||||
_fat_print_directory_loop_next_sector: ; end fo sector. read next sector from disk
|
||||
POP HL ;clear stack from old hl
|
||||
LD H,0
|
||||
LD L,1
|
||||
call _fat_math_sector_add_16 ;increment sector
|
||||
|
||||
LD DE,(MEM_FAT_COUNT1) ; decrement sector count (max FAT length)
|
||||
DEC DE
|
||||
LD (MEM_FAT_COUNT1),DE
|
||||
LD A,D
|
||||
OR E
|
||||
JP Z, _fat_print_directory_loop_break_dirty ; if DE is 0, mmax is reached. End here
|
||||
|
||||
LD HL,MEM_IDE_POINTER ;read next sector
|
||||
LD B,1
|
||||
|
||||
LD DE, MEM_IDE_BUFFER ;where to store data?
|
||||
call read_lba_sector
|
||||
|
||||
LD HL, MEM_IDE_BUFFER ;set buffer start
|
||||
LD C,16 ;set entries counter
|
||||
JP _fat_print_directory_loop
|
||||
|
||||
_fat_print_directory_loop_break
|
||||
POP HL
|
||||
_fat_print_directory_loop_break_dirty
|
||||
; ld hl, [str_sum]
|
||||
; call print_str ;print
|
||||
; ld a,c
|
||||
; call print_a_hex
|
||||
; ld hl, [str_files]
|
||||
; call print_str ;print
|
||||
ret
|
||||
|
||||
; fat change directory
|
||||
; relative path
|
||||
; DE pointer to path
|
||||
fat_cd_single:
|
||||
push de
|
||||
; check if user wants to go back (input = '..')
|
||||
ld a,(de)
|
||||
cp '.'
|
||||
jr nz, _fat_cd_navigate; if not, skip
|
||||
inc de ;check next
|
||||
ld a,(de)
|
||||
cp '.'
|
||||
jr nz, _fat_cd_navigate; if not, skip
|
||||
ld a,(var_dir+79) ;last byte contains depth
|
||||
or a; Test if 0
|
||||
jp z, _fat_cd_navigate_error ;cannot go back any more (already at root)
|
||||
; check if .. exists in directory
|
||||
ld a,'.' ;prepare filename buffer
|
||||
ld hl,[MEM_FAT_TMPFNAME]
|
||||
ld (hl),a
|
||||
inc hl
|
||||
ld (hl),a
|
||||
inc hl
|
||||
ld a,0x20 ;clear char 3-11
|
||||
ld b,11
|
||||
_fat_cd_navigate_goback_fl:
|
||||
ld (hl),a
|
||||
inc hl
|
||||
djnz _fat_cd_navigate_goback_fl ;fill loop end
|
||||
call fat_openfile_noprepare ;load file table (only 1st sector needed)
|
||||
or a ;check for error
|
||||
jp nz, _fat_cd_navigate_error ;entry not found exception
|
||||
|
||||
|
||||
; find end of path
|
||||
ld hl,[var_dir+3] ;current position
|
||||
ld bc,76
|
||||
ld a,0x00 ;termination char
|
||||
cpir ;find end
|
||||
jp po,_fat_cd_navigate_inerror ;in case of error, abort
|
||||
;hl is now at end of string
|
||||
ld bc,76
|
||||
ld a,'\' ;seperation char
|
||||
cpdr ;serach backwards for "/"
|
||||
jp po,_fat_cd_navigate_inerror ;in case of error, abort
|
||||
;hl is now at end of string
|
||||
inc hl
|
||||
xor a
|
||||
ld (hl),a ;set termination char
|
||||
inc hl
|
||||
ld (hl),a ;set termination char
|
||||
ld a,(var_dir+79)
|
||||
dec a
|
||||
ld (var_dir+79),a ;decrement dir depth counter
|
||||
|
||||
pop de
|
||||
|
||||
ld hl,[var_dir+2]
|
||||
ld a,'\'
|
||||
ld (hl),a ;set first /
|
||||
|
||||
ld hl,MEM_FAT_OF0_DATSEC ;setup directory pointer
|
||||
ld de,MEM_FAT_CURRDIR
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
|
||||
ret
|
||||
|
||||
_fat_cd_navigate
|
||||
pop de ;get pointer to directory namme
|
||||
push de ;and re-store it for next use
|
||||
call fat_openfile ;find 'file' in current directory
|
||||
_fat_cd_navigate_findsec
|
||||
or a
|
||||
jp nz, _fat_cd_navigate_error ;entry not found
|
||||
ld a, (MEM_FAT_OF0_ATTRIBUTE)
|
||||
cp 0x10
|
||||
jp nz, _fat_cd_navigate_errfile
|
||||
ld a,(var_dir+79)
|
||||
inc a
|
||||
ld (var_dir+79),a ;increment dir depth counter
|
||||
ld hl,[var_dir+2] ;load start of path string
|
||||
ld a,0 ;load termination char
|
||||
ld bc,76 ;max length of string
|
||||
cpir ;find end of path string
|
||||
dec hl
|
||||
jp po,_fat_cd_navigate_inerror ;in case of error, abort
|
||||
;HL now has last element, BC has remaining max length
|
||||
ld a,(var_dir+79) ;last byte contains depth
|
||||
cp 1 ;if first path, skip /
|
||||
jr z, _fat_cd_navigate_findsec_skipslash
|
||||
ld a,'\'
|
||||
ld (hl),a
|
||||
inc hl
|
||||
_fat_cd_navigate_findsec_skipslash
|
||||
pop de ;get argument from stack
|
||||
ex de,hl
|
||||
push de ;store start to stack
|
||||
;HL now has start of input string, DE has end of current path
|
||||
ld bc,09 ;maximum length of directory name +1
|
||||
_fat_cd_navigate_l2: ;copy new subdirectory
|
||||
ldi ;copy
|
||||
jp po,_fat_cd_navigate_inerrorS ;in case of error, abort
|
||||
ld a,(hl) ;check next char
|
||||
cp '\' ;end at '\'
|
||||
jr z, _fat_cd_navigate_end ;else next byte
|
||||
or a ;or and at 0x00
|
||||
jr z, _fat_cd_navigate_end ;else next byte
|
||||
jr _fat_cd_navigate_l2
|
||||
_fat_cd_navigate_end:
|
||||
xor a
|
||||
ld (de),a ;set last byte to 0x00 (termination)
|
||||
ld hl,MEM_FAT_OF0_DATSEC
|
||||
;setup directory pointer
|
||||
ld de,MEM_FAT_CURRDIR
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
pop de ;stack cleanup
|
||||
ret
|
||||
|
||||
_fat_cd_navigate_error:
|
||||
ld hl,[_fat_cd_navigate_error_str]
|
||||
call print_str
|
||||
pop de
|
||||
ret
|
||||
|
||||
_fat_cd_navigate_inerrorS: ;with path reset
|
||||
pop de ;restore former path
|
||||
dec de ;change pointer to remove previous '\' as well
|
||||
xor a ;clear a to 0x00
|
||||
ld (de),a ;set last byte to 0x00 (termination)
|
||||
jr _fat_cd_navigate_inerrore
|
||||
_fat_cd_navigate_inerror: ;without path reset
|
||||
pop de
|
||||
_fat_cd_navigate_inerrore:
|
||||
ld hl,[_fat_cd_navigate_inputerr_str]
|
||||
call print_str
|
||||
ret
|
||||
_fat_cd_navigate_errfile:
|
||||
pop de
|
||||
ld hl,[_fat_cd_navigate_errfile_str]
|
||||
call print_str
|
||||
ret
|
||||
|
||||
_fat_cd_navigate_error_str:
|
||||
db 10,13,"No such directory!",10,13,0
|
||||
_fat_cd_navigate_inputerr_str:
|
||||
db 10,13,"Invalid input!",10,13,0
|
||||
_fat_cd_navigate_errfile_str:
|
||||
db 10,13,"Cannot cd to file!",10,13,0
|
||||
|
||||
;=================== UTIL Functions ===========================
|
||||
; 32 Bit addition to pointer
|
||||
; HL has value
|
||||
;deprecated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
_fat_math_sector_add_16:
|
||||
ld (MEM_FAT_TMPPOINTER), hl
|
||||
xor a
|
||||
ld (MEM_FAT_TMPPOINTER+2),a
|
||||
ld (MEM_FAT_TMPPOINTER+3),a
|
||||
|
||||
ld de,[MEM_FAT_TMPPOINTER]
|
||||
ld bc,[MEM_IDE_POINTER]
|
||||
call _fat_math_add32
|
||||
ret
|
||||
;deprecated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
;hl contains pointer
|
||||
_fat_increment_32
|
||||
ld a,(HL) ; byte 0
|
||||
add 1
|
||||
ld (hl),a
|
||||
inc hl
|
||||
ld a,(HL) ; byte 1
|
||||
adc 0
|
||||
ld (hl),a
|
||||
inc hl
|
||||
ld a,(HL) ; byte 2
|
||||
adc 0
|
||||
ld (hl),a
|
||||
inc hl
|
||||
ld a,(HL) ; byte 3
|
||||
adc 0
|
||||
ld (hl),a
|
||||
ret
|
||||
;bc contains pointer to a (also result)
|
||||
;de contains pointer to b
|
||||
_fat_math_add32
|
||||
push hl
|
||||
push bc
|
||||
push de
|
||||
ld a,(de) ; load lower 16bit for B int from (DE) to HL
|
||||
ld l,a
|
||||
inc de
|
||||
ld a,(de)
|
||||
ld h,a
|
||||
inc de
|
||||
; HL, DE dirty
|
||||
ld a,(bc) ; load lower 16bit for A int from (BC) to DE
|
||||
ld e,a
|
||||
inc bc
|
||||
ld a,(bc)
|
||||
ld d,a
|
||||
; HL now contains A, DE now contains D
|
||||
add hl,de ;add lower bytes, store carry
|
||||
pop de ;restore pointers
|
||||
pop bc ;both now cointain first byte of long-value
|
||||
ld a,l ;store lower result in (bc)
|
||||
ld (bc),a
|
||||
inc bc
|
||||
ld a,h
|
||||
ld (bc),a
|
||||
inc bc
|
||||
inc de ;also increment de to next byte
|
||||
inc de
|
||||
; DE and HL now start at the upper byte
|
||||
push bc
|
||||
push de
|
||||
ld a,(de) ; load upper 16bit for B
|
||||
ld l,a
|
||||
inc de
|
||||
ld a,(de)
|
||||
ld h,a
|
||||
inc de
|
||||
ld a,(bc) ; load upper 16bit for A
|
||||
ld e,a
|
||||
inc bc
|
||||
ld a,(bc)
|
||||
ld d,a
|
||||
adc hl,de ;add upper bytes, store carry
|
||||
pop de
|
||||
pop bc
|
||||
ld a,l ;store lower result in (bc)
|
||||
ld(bc),a
|
||||
inc bc
|
||||
ld a,h
|
||||
ld(bc),a
|
||||
pop hl
|
||||
ret
|
||||
|
||||
|
||||
; Multiply 16-bit values (with 32-bit result)
|
||||
; Operands BC, DE
|
||||
; Result -> BCHL
|
||||
_fat_math_mul32:
|
||||
ld a,c
|
||||
ld c,b
|
||||
ld hl,0
|
||||
ld b,16
|
||||
_fat_math_mul32_l:
|
||||
add hl,hl
|
||||
rla
|
||||
rl c
|
||||
jr nc,_fat_math_mul32_noadd
|
||||
add hl,de
|
||||
adc a,0
|
||||
jp nc,_fat_math_mul32_noadd
|
||||
inc c
|
||||
_fat_math_mul32_noadd:
|
||||
djnz _fat_math_mul32_l
|
||||
ld b,c
|
||||
ld c,a
|
||||
ret
|
||||
|
||||
; reset LBA pointer to first sector in selected partition
|
||||
fat_reset_pointer:
|
||||
call ideif_get_drv_pointer
|
||||
inc ix
|
||||
inc ix
|
||||
push ix
|
||||
pop hl ;copy poiter to hl
|
||||
ld de, MEM_IDE_POINTER
|
||||
jr fat_copy_lba_pointer
|
||||
|
||||
; resets LBA pointer (4-byte) to partition start
|
||||
; HL = from here
|
||||
; DE = to this destimation
|
||||
fat_copy_lba_pointer:
|
||||
PUSH BC
|
||||
LD B,0
|
||||
LD C,4
|
||||
LDIR
|
||||
POP BC
|
||||
ret
|
||||
|
||||
317
OperatingSystem/.unused/software/include/fat16_file.s
Normal file
317
OperatingSystem/.unused/software/include/fat16_file.s
Normal file
@@ -0,0 +1,317 @@
|
||||
|
||||
|
||||
;1. find sector for given cluster
|
||||
;2. read sector
|
||||
;3. store first data sector to MEM_FAT_OF0_DATSEC
|
||||
;4. set MEM_FAT_OF0_DATREM to amount uf sectors per cluster
|
||||
;5. find next cluster in FAt and update MEM_FAT_OF0_CCLUST
|
||||
|
||||
|
||||
; gets sector in FAT table for the cluster stored in MEM_FAT_OF0_CCLUST
|
||||
; store result in MEM_FAT_OF0_FATSEC
|
||||
; stores next cluster in MEM_FAT_OF0_CCLUST
|
||||
fat_getfatsec:
|
||||
ld HL,(MEM_FAT_OF0_CCLUST) ;load cluster
|
||||
ld a,h ;if not 0x0000
|
||||
or l
|
||||
jp nz, _fat_getfatsec_notroot
|
||||
;if 0x0000, goto root directory
|
||||
ld hl,MEM_FAT_ROOTSTART
|
||||
ld de,MEM_FAT_OF0_DATSEC
|
||||
ldi ;quick and dirty hack to go back to root directory
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ret
|
||||
|
||||
_fat_getfatsec_notroot:
|
||||
ld HL,(MEM_FAT_OF0_CCLUST) ;load cluster
|
||||
;each sector contains 256 clusters
|
||||
;first 8bits are not needed (/256)
|
||||
ld a,h ;divide by 256
|
||||
ld l,a
|
||||
xor a
|
||||
ld h,a
|
||||
|
||||
ld bc,(MEM_FAT_RESERVED) ;add reserved sectors
|
||||
add hl,bc
|
||||
ld(MEM_FAT_OF0_FATSEC+0),hl;store sector
|
||||
xor a
|
||||
ld(MEM_FAT_OF0_FATSEC+2),a
|
||||
ld(MEM_FAT_OF0_FATSEC+3),a
|
||||
|
||||
call ideif_get_drv_pointer
|
||||
inc ix
|
||||
inc ix
|
||||
push ix
|
||||
pop de ;copy poiter to hl
|
||||
ld bc,[MEM_FAT_OF0_FATSEC]
|
||||
call _fat_math_add32 ;MEM_FAT_OF0_FATSEC now contains the correct sector
|
||||
;in the FAT
|
||||
|
||||
;read FAT sector
|
||||
ld hl,MEM_FAT_OF0_FATSEC ;read next sector
|
||||
ld b,1
|
||||
LD DE, MEM_IDE_BUFFER ;where to store data?
|
||||
call read_lba_sector
|
||||
|
||||
;calculate data sector
|
||||
;multiply cluster by length of cluster
|
||||
xor a ;clear carry
|
||||
ld a,(MEM_FAT_CLUSTERLEN)
|
||||
ld b,0
|
||||
ld c,a
|
||||
ld de,(MEM_FAT_OF0_CCLUST) ;load cluster number
|
||||
dec de ; sub 2 becaus fat starts at 3
|
||||
dec de
|
||||
call _fat_math_mul32
|
||||
; BCHL contains result -> store to PTR.MEM_FAT_OF0_DATSEC
|
||||
ld (MEM_FAT_OF0_DATSEC+0),hl
|
||||
ld (MEM_FAT_OF0_DATSEC+2),bc
|
||||
|
||||
; add start of data region to addr
|
||||
ld bc,[MEM_FAT_OF0_DATSEC]
|
||||
ld de,[MEM_FAT_DATASTART]
|
||||
call _fat_math_add32 ;MEM_FAT_OF0_FATSEC now contains the correct sector
|
||||
;in the FAT
|
||||
;MEM_FAT_OF0_DATSEC now has the first sector of the selected cluster
|
||||
|
||||
;reset MEM_FAT_OF0_DATREM to default cluster length
|
||||
ld a,(MEM_FAT_CLUSTERLEN)
|
||||
ld l,a
|
||||
ld h,0
|
||||
ld (MEM_FAT_OF0_DATREM), hl
|
||||
|
||||
;get next cluster
|
||||
;calculate offset address
|
||||
ld a,(MEM_FAT_OF0_CCLUST)
|
||||
RLA ;shift to left (x2)
|
||||
ld l, a
|
||||
ld a,0
|
||||
RLA ;shift in carry flag
|
||||
ld h,a
|
||||
ld de,MEM_IDE_BUFFER
|
||||
add hl,de
|
||||
;copy pointer (hl to de)
|
||||
ld de,MEM_FAT_OF0_CCLUST
|
||||
ldi ;copy byte for next cluster from FAT
|
||||
ldi
|
||||
ret
|
||||
;store data
|
||||
|
||||
; reads single sector of file
|
||||
; must run fat_readfilesec before to initialize
|
||||
; if a ix 0x00, success
|
||||
; if a is 0xFF, end reached
|
||||
fat_readfilesec:
|
||||
call fat_print_dbg
|
||||
ld hl,[MEM_FAT_OF0_DATSEC]
|
||||
ld b,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
|
||||
call _fat_increment_32 ;***
|
||||
ld hl,(MEM_FAT_OF0_DATREM) ;reduce counter
|
||||
xor a
|
||||
ld de,1
|
||||
sbc hl,de ;decrement counter
|
||||
ld (MEM_FAT_OF0_DATREM),hl ;store decremented counter
|
||||
ret nz ;when not zero, exit function
|
||||
;if zero:
|
||||
ld a, 0xFF ;preload error code
|
||||
ld hl,(MEM_FAT_OF0_CCLUST) ;check next chunk
|
||||
ld de,0xFFFF ;end mark
|
||||
sbc hl,de ;if Z match
|
||||
ret z ;If 0xFFFF, end is reched. Return
|
||||
;if next cluster available:
|
||||
xor a
|
||||
call fat_getfatsec ; read next cluster information
|
||||
ret
|
||||
|
||||
;-------------------------------------
|
||||
; FAT open file
|
||||
;
|
||||
; DE pointer to file name
|
||||
;-------------------------------------
|
||||
fat_openfile:
|
||||
PUSH DE
|
||||
;MEM_FAT_TMPFNAME now has valid text to compare
|
||||
LD HL,[MEM_FAT_TMPFNAME]
|
||||
call format_filename_fat16
|
||||
POP DE
|
||||
fat_openfile_noprepare:
|
||||
PUSH DE
|
||||
;prepare pointer
|
||||
ld hl,MEM_FAT_CURRDIR
|
||||
ld de,MEM_IDE_POINTER
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
ldi
|
||||
|
||||
LD A,(MEM_FAT_DIRSEC) ;init counter for FAT sectors
|
||||
LD (MEM_FAT_COUNT1),A
|
||||
|
||||
LD HL,MEM_IDE_POINTER ;read first sector
|
||||
LD B,1
|
||||
LD DE, MEM_IDE_BUFFER ;where to store data?
|
||||
call read_lba_sector
|
||||
|
||||
LD HL, MEM_IDE_BUFFER ;set buffer start
|
||||
LD C,16 ;set entries counter
|
||||
|
||||
_fat_lfs_loop:
|
||||
LD DE,[MEM_FAT_TMPFNAME]
|
||||
CALL compare_filename
|
||||
JR C, _fat_lfs_loop_compare_match ;on match
|
||||
|
||||
; prepare next entry
|
||||
DEC C ;next sector after 16 entries
|
||||
JR Z,_fat_lfs_loop_compare_next_sector
|
||||
LD DE, 32 ;length of entry
|
||||
ADD HL,DE ;increment
|
||||
JP _fat_lfs_loop
|
||||
|
||||
_fat_lfs_loop_compare_next_sector:
|
||||
ld hl,[MEM_IDE_POINTER]
|
||||
call _fat_increment_32 ;increment sector
|
||||
|
||||
LD A,(MEM_FAT_COUNT1) ; decrement sector count (max FAT length)
|
||||
DEC A
|
||||
LD (MEM_FAT_COUNT1),A
|
||||
JP Z, _fat_lfs_loop_compare_end ; if DE is 0, mmax is reached. End here
|
||||
;call print_a_hex
|
||||
|
||||
LD HL,MEM_IDE_POINTER ;read next sector
|
||||
LD B,1
|
||||
LD DE, MEM_IDE_BUFFER ;where to store data?
|
||||
call read_lba_sector
|
||||
|
||||
LD HL, MEM_IDE_BUFFER ;set buffer start
|
||||
LD C,16 ;set entries counter
|
||||
|
||||
ld a,(HL)
|
||||
or a
|
||||
jp z, _fat_lfs_loop_compare_end ;skip empty sectors
|
||||
|
||||
JP _fat_lfs_loop
|
||||
|
||||
_fat_lfs_loop_compare_end:
|
||||
POP DE
|
||||
;LD HL, [str_file_notfound]
|
||||
;CALL print_str ;print
|
||||
ld a,0xFF
|
||||
RET
|
||||
|
||||
_fat_lfs_loop_compare_match:
|
||||
; get entry
|
||||
POP DE
|
||||
|
||||
; HL points to Start of Table item
|
||||
PUSH HL
|
||||
POP IX
|
||||
; get important information
|
||||
ld a,(ix+0x1B) ;first cluster number
|
||||
ld (MEM_FAT_OF0_CCLUST+1),a
|
||||
ld a,(ix+0x1A)
|
||||
ld (MEM_FAT_OF0_CCLUST+0),a
|
||||
ld a,(ix+0x0B)
|
||||
ld (MEM_FAT_OF0_ATTRIBUTE+0),a
|
||||
|
||||
xor a ;clear carry ;set MEM_FAT_OF0_DATREM to remaining sectors
|
||||
ld a,(ix+0x1F) ;cluste length shift by 256
|
||||
rra
|
||||
ld (MEM_FAT_FILEREMAIN+2),a
|
||||
ld a,(ix+0x1E)
|
||||
rra
|
||||
ld (MEM_FAT_FILEREMAIN+1),a
|
||||
ld a,(ix+0x1D)
|
||||
rra
|
||||
ld (MEM_FAT_FILEREMAIN+0),a
|
||||
ld a,0
|
||||
ld (MEM_FAT_FILEREMAIN+3),a
|
||||
call fat_getfatsec ;get sector information
|
||||
;call print_newLine
|
||||
|
||||
;LD B,8
|
||||
;call print_str_fixed
|
||||
;ld A,'.'
|
||||
;call print_char
|
||||
;LD B,3
|
||||
;call print_str_fixed
|
||||
;LD HL, [str_file_found]
|
||||
;CALL print_str ;print
|
||||
xor a
|
||||
RET
|
||||
|
||||
|
||||
; compares filenames
|
||||
; HL points to name1
|
||||
; DE points to name2
|
||||
; Carry is set if match
|
||||
; Destroys DE, AF
|
||||
compare_filename:
|
||||
PUSH HL
|
||||
push BC
|
||||
LD B, 11 ;Counter
|
||||
_compare_filename_loop:
|
||||
LD A,(DE)
|
||||
LD C,A
|
||||
LD A,(HL)
|
||||
INC HL
|
||||
INC DE
|
||||
XOR C ;check if identical (should return 0)
|
||||
JR NZ, _compare_filename_nomatch
|
||||
djnz _compare_filename_loop ;if not last, continue
|
||||
POP BC
|
||||
POP HL
|
||||
SCF
|
||||
RET
|
||||
_compare_filename_nomatch:
|
||||
POP BC
|
||||
POP HL
|
||||
XOR A ; clear carry flag
|
||||
RET
|
||||
|
||||
; formats filename to 8+3 format
|
||||
; DE points to source filename to string
|
||||
; HL points to destination
|
||||
format_filename_fat16:
|
||||
LD B, 11 ;counter
|
||||
PUSH HL
|
||||
LD A, ' '
|
||||
_format_filename_fat16_clean:
|
||||
LD (HL),A
|
||||
INC HL
|
||||
DJNZ _format_filename_fat16_clean
|
||||
POP HL ; continue with copy
|
||||
LD B, 13
|
||||
_format_filename_fat16_loop:
|
||||
LD A, (DE) ; load byte
|
||||
OR A
|
||||
RET Z ;exit on 0byte
|
||||
DEC B ;reduce counter
|
||||
RET Z ;exit after 12 bytes 8+.+3
|
||||
CP '.' ; check if dot
|
||||
JR NZ, _format_filename_fat16_loop_copy ; if not continue as usual
|
||||
INC DE ;else skip char
|
||||
_format_filename_fat16_loop_skip_8:
|
||||
LD A,B
|
||||
CP 5
|
||||
JR C, _format_filename_fat16_loop
|
||||
INC HL
|
||||
DEC B
|
||||
JR _format_filename_fat16_loop_skip_8
|
||||
|
||||
_format_filename_fat16_loop_copy:
|
||||
LD A, (DE) ; load byte
|
||||
LD (HL), A ; copy byte
|
||||
INC HL
|
||||
INC DE
|
||||
JP _format_filename_fat16_loop
|
||||
|
||||
str_file_notfound:
|
||||
db "File not found!",13,10,0
|
||||
|
||||
str_file_found:
|
||||
db " File located!",13,10,0
|
||||
34
OperatingSystem/.unused/software/include/regdump.s
Normal file
34
OperatingSystem/.unused/software/include/regdump.s
Normal file
@@ -0,0 +1,34 @@
|
||||
regdump:
|
||||
|
||||
PUSH BC
|
||||
PUSH DE
|
||||
PUSH HL
|
||||
PUSH AF
|
||||
|
||||
CALL PRINTINLINE
|
||||
defb "REGDUMP",10,13,"A: 0x",0
|
||||
call print_a_hex
|
||||
CALL PRINTINLINE
|
||||
defb " F: 0x",0
|
||||
POP BC
|
||||
PUSH BC
|
||||
LD A,C
|
||||
call print_a_hex
|
||||
|
||||
CALL PRINTINLINE
|
||||
defb 13,10,"BC: 0x",0
|
||||
|
||||
|
||||
|
||||
ld a,b
|
||||
call print_a_hex
|
||||
ld a,c
|
||||
call print_a_hex
|
||||
CALL PRINTINLINE
|
||||
defb 13,10,0
|
||||
|
||||
POP AF
|
||||
POP HL
|
||||
POP DE
|
||||
POP BC
|
||||
|
||||
5
OperatingSystem/.unused/software/properties.env
Normal file
5
OperatingSystem/.unused/software/properties.env
Normal file
@@ -0,0 +1,5 @@
|
||||
export OPT_GEN_SYMBOLTABLE=0
|
||||
export OPT_GEN_MONFILE=1
|
||||
export OPT_GEN_OBJFILE=1
|
||||
export OPT_WRITEROM=0
|
||||
export FILENAME=test
|
||||
107
OperatingSystem/.unused/software/test.asm
Normal file
107
OperatingSystem/.unused/software/test.asm
Normal file
@@ -0,0 +1,107 @@
|
||||
.include "extern_symbols.s" ;include monitor symbols.
|
||||
|
||||
CS_VT82C42_DATA .EQU 0xF0
|
||||
CS_VT82C42_CTRL .EQU 0xF1
|
||||
|
||||
org 0x6000
|
||||
;VT82C42
|
||||
|
||||
ld a, 0xA7 ;Disable Mouse
|
||||
out (CS_VT82C42_CTRL), A
|
||||
ld a, 0xAD ;Disable Keyboard
|
||||
out (CS_VT82C42_CTRL), A
|
||||
_keyboard_init_flush_buffer:
|
||||
in a,(CS_VT82C42_DATA) ;Read buffer
|
||||
in a,(CS_VT82C42_CTRL) ;Read status byte
|
||||
bit 0,a ;Test if buffer is empty
|
||||
jr nz, _keyboard_init_flush_buffer
|
||||
;buffer is now flushed. Now set the Controller Configuration Byte
|
||||
|
||||
ld a, 0x60 ;next byte is command byte register write
|
||||
ld b, 11111100b ;Disable bits 0,1,6 (disable IRQ and Translation)
|
||||
call keyb_cmd_wr
|
||||
|
||||
;Perform Controller Self Test
|
||||
ld a, 0xAA
|
||||
call keyb_cmd_rd
|
||||
cp 0x55
|
||||
jr nz, _keyboard_init_failed
|
||||
|
||||
;Perform Interface Tests
|
||||
ld a, 0xAB
|
||||
call keyb_cmd_rd
|
||||
or a
|
||||
jr nz, _keyboard_init_failed
|
||||
|
||||
;Enable Devices
|
||||
ld a,0xAE
|
||||
out (CS_VT82C42_CTRL), A
|
||||
call keyb_wait_ibf_empty
|
||||
|
||||
;Test if device is present Devices
|
||||
ld a,0xEE
|
||||
out (CS_VT82C42_DATA), A ;Send echo to keboard (0xEE command)
|
||||
call keyb_wait_ibf_empty
|
||||
call keyb_wait_obf
|
||||
in a,(CS_VT82C42_DATA)
|
||||
cp a, 0xEE
|
||||
jr z, _keyboard_init_okay ; 0xFC -> Success. Init done!
|
||||
;Else device error
|
||||
ld hl, [STR_keyboard_init_failed]
|
||||
call print_str
|
||||
ret
|
||||
_keyboard_init_failed:
|
||||
LD HL, [STR_keyboard_init_err]
|
||||
CALL print_str
|
||||
RET
|
||||
_keyboard_init_dev_missing:
|
||||
LD HL, [STR_keyboard_init_missing]
|
||||
CALL print_str
|
||||
RET
|
||||
_keyboard_init_okay:
|
||||
LD HL, [STR_keyboard_init_okay]
|
||||
CALL print_str
|
||||
RET
|
||||
|
||||
; a contains command
|
||||
; b conatins data
|
||||
keyb_cmd_wr:
|
||||
out (CS_VT82C42_CTRL),a ;write command byte
|
||||
ld a, b
|
||||
out (CS_VT82C42_DATA),a
|
||||
ret
|
||||
|
||||
; a contains command
|
||||
; a returns data
|
||||
keyb_cmd_rd:
|
||||
out (CS_VT82C42_CTRL),a ;write command byte
|
||||
_keyb_cmd_rd_l1:
|
||||
in a, (CS_VT82C42_CTRL) ;read status
|
||||
call print_a_hex
|
||||
rra
|
||||
jr nc, _keyb_cmd_rd_l1 ;wait until OBF is set (data avail)
|
||||
in a, (CS_VT82C42_DATA)
|
||||
ret
|
||||
|
||||
keyb_wait_ibf_empty:
|
||||
in a, (CS_VT82C42_CTRL) ;read status
|
||||
rra
|
||||
rra
|
||||
jr c, keyb_wait_ibf_empty ;if IBF, wait
|
||||
ret
|
||||
|
||||
keyb_wait_obf:
|
||||
in a, (CS_VT82C42_CTRL) ;read status
|
||||
rra
|
||||
jr nc, keyb_wait_obf ;if IBF, wait
|
||||
ret
|
||||
|
||||
;Status message strings
|
||||
STR_keyboard_init_okay:
|
||||
.BYTE "PS/2 Keyboard initialized.",0
|
||||
STR_keyboard_init_err:
|
||||
.BYTE "PS/2 Controller error! System HALT!",0
|
||||
STR_keyboard_init_failed:
|
||||
.BYTE "PS/2 Keyboard error! System HALT!",0
|
||||
STR_keyboard_init_missing:
|
||||
.BYTE "PS/2 no keyboard found!",0
|
||||
327
OperatingSystem/.unused/software/test_iic.asm
Normal file
327
OperatingSystem/.unused/software/test_iic.asm
Normal file
@@ -0,0 +1,327 @@
|
||||
.include "extern_symbols.s" ;include monitor symbols.
|
||||
org 0xB000
|
||||
CS_PIO_BD .EQU 0xF5
|
||||
CS_PIO_BC .EQU 0xF7
|
||||
CS_PIO_AD .EQU 0xF4
|
||||
CS_PIO_AC .EQU 0xF6
|
||||
|
||||
CS_I2C_S1 .EQU 0xF3
|
||||
CS_I2C_SX .EQU 0xF2
|
||||
|
||||
IIC_RTC equ 11010000b
|
||||
|
||||
IIC_INIT:
|
||||
LD A,0xCF
|
||||
OUT (CS_PIO_AC), A
|
||||
LD A,11110101b
|
||||
OUT (CS_PIO_AC), A
|
||||
|
||||
LD A,00000000b ; Reset PCF8584 minimum 30 clock cycles
|
||||
OUT (CS_PIO_AD), A
|
||||
LD BC,0x1000
|
||||
CALL PAUSE_LOOP
|
||||
LD A,0000010b
|
||||
OUT (CS_PIO_AD), A
|
||||
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
|
||||
LD A, 0x80 ;S1 -> Select S0, PIN disabled, ESO = 0, Interrupt disabled, STA, STA, ACK = 0
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL SlowAccess
|
||||
CALL SlowAccess
|
||||
|
||||
LD A,0x55 ;S0 -> Loads byte 55H into register S0'; effective own address becomes AAH
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL SlowAccess
|
||||
|
||||
LD A, 0xA0 ;S1 -> Loads byte A0H into register S1, i.e. next byte will be loaded into the clock control register S2.
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL SlowAccess
|
||||
|
||||
|
||||
LD A,0x00 ;Load 18H into S2 register (clock control - 8 MHz, 90 KHz)
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL SlowAccess
|
||||
|
||||
LD A,0xC1 ;S1 -> loads byte C1H into register S1; register enable
|
||||
;serial interface, set I 2C-bus into idle mode;
|
||||
;SDA and SCL are HIGH. The next write or read
|
||||
;operation will be to/from data transfer register
|
||||
;S0 if A0 = LOW.;
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL SlowAccess
|
||||
|
||||
|
||||
|
||||
;CALL force_stop
|
||||
JP PROMPT_BEGIN
|
||||
|
||||
LD BC,$0100
|
||||
CALL PAUSE_LOOP
|
||||
|
||||
|
||||
; Send test message to RTC
|
||||
|
||||
LD DE, 0xC000 ; Set I2C Buffer Location
|
||||
LD A,0x00
|
||||
LD (DE),A
|
||||
;call regdump
|
||||
|
||||
LD B, IIC_RTC ; Set I2C Address
|
||||
LD A, 1 ; Set I2C Buffer length
|
||||
call i2c_send
|
||||
|
||||
LD DE, 0xC010
|
||||
LD B, IIC_RTC
|
||||
LD A, 7
|
||||
call i2c_read
|
||||
|
||||
|
||||
|
||||
JP PROMPT_BEGIN
|
||||
|
||||
|
||||
;CLK_ENABLE:
|
||||
; LD DE, 0xC000 ; Set I2C Buffer Location
|
||||
; LD A,0x00
|
||||
; LD (0xC000),A
|
||||
; LD (0xC001),A
|
||||
; ;call regdump
|
||||
;
|
||||
; LD B, IIC_RTC ; Set I2C Address
|
||||
; LD A, 2 ; Set I2C Buffer length
|
||||
; call i2c_send
|
||||
; JP PROMPT_BEGIN
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; i2c_send
|
||||
;
|
||||
; Sends data over the i2c bus
|
||||
; A contains BYTE COUNTER
|
||||
; B contains ADDRESS
|
||||
; DE contains location of Data Buffer
|
||||
;------------------------------------------------------------------------------
|
||||
i2c_send:
|
||||
; CALL PRINTINLINE;
|
||||
; defb "SEND A",10,13,0
|
||||
PUSH BC
|
||||
PUSH AF
|
||||
CALL i2c_bus_rdy
|
||||
; CALL PRINTINLINE
|
||||
; defb "SEND START",10,13,0
|
||||
LD A,B ;Load 'slave address' into S0 register:
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL SlowAccess
|
||||
|
||||
LD A, 0xC5 ;Load C5H into S1. 'C5H' = PCF8584 generates
|
||||
;the 'START' condition and clocks out the slave
|
||||
;address and the clock pulse for slave acknowledgement.
|
||||
OUT (CS_I2C_S1),A
|
||||
POP AF
|
||||
LD C,A
|
||||
INC C
|
||||
i2c_send_1: ; LOOP 1 : Wait for bus ready
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; Is bus free? (S1 ~BB=1?)
|
||||
JR NZ,i2c_send_1 ; No - loop
|
||||
BIT 4,A ; slave acknowledged? (LRB = 0?)
|
||||
JR NZ, i2c_send_stop ; if not, cancel transmission
|
||||
LD A,(DE) ; Load next byte from buffer
|
||||
INC DE
|
||||
DEC C
|
||||
JR Z, i2c_send_stop ; if counter = 0, exit loop
|
||||
OUT (CS_I2C_SX),A ; Send byte
|
||||
JR i2c_send_1 ; if counter > 0, loop again
|
||||
i2c_send_stop:
|
||||
LD A, 0xC3 ;STOP
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL SlowAccess
|
||||
POP BC
|
||||
RET
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; i2c_read
|
||||
;
|
||||
; Sends data over the i2c bus
|
||||
; A contains BYTE COUNTER
|
||||
; B contains ADDRESS
|
||||
; DE contains location of Data Buffer
|
||||
;------------------------------------------------------------------------------
|
||||
i2c_read:
|
||||
PUSH DE
|
||||
PUSH BC
|
||||
PUSH AF
|
||||
LD A,B ;Load 'slave address' into S0 register:
|
||||
OR 0x01 ;Set RW Bit for read operation
|
||||
OUT (CS_I2C_SX),A
|
||||
CALL SlowAccess
|
||||
CALL i2c_bus_rdy ; Is bus ready
|
||||
LD A, 0xC5 ;Load C5H into S1. 'C5H' = PCF8584 generates
|
||||
;the 'START' condition and clocks out the slave
|
||||
;address and the clock pulse for slave acknowledgement.
|
||||
OUT (CS_I2C_S1),A
|
||||
;Setup counter
|
||||
POP AF
|
||||
LD C,A ; Load BYTE COUNTER into C
|
||||
INC C ; Offset C by 1
|
||||
i2c_read_1: ;Wait for PIN = 0
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; S1 PIN=1?
|
||||
JR NZ,i2c_read_1 ; No - loop
|
||||
BIT 3,A ; S1 LRB=0? slave ACK?
|
||||
JR NZ, i2c_read_error ; No ACK -> an error has occured
|
||||
DEC C
|
||||
LD A, C
|
||||
DEC A ;If n = m − 1?
|
||||
JR Z, i2c_read_last
|
||||
IN A,(CS_I2C_SX)
|
||||
LD (DE),A
|
||||
INC DE
|
||||
JR i2c_read_1
|
||||
i2c_read_last: ;read last byte
|
||||
LD A, 0x40
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL SlowAccess
|
||||
IN A,(CS_I2C_SX) ;receives the final data byte. Neg. ACK is also sent.
|
||||
LD (DE),A
|
||||
INC DE
|
||||
i2c_read_last_1:
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; S1 PIN=1?
|
||||
JR NZ,i2c_read_last_1 ; No - loop
|
||||
|
||||
i2c_read_error:
|
||||
NOP
|
||||
i2c_read_stop:
|
||||
LD A, 0xC3
|
||||
OUT (CS_I2C_S1),A
|
||||
CALL SlowAccess
|
||||
IN A,(CS_I2C_SX) ;transfers the final data byte from the
|
||||
;data buffer to accumulator.
|
||||
CALL SlowAccess
|
||||
LD (DE),A
|
||||
POP BC
|
||||
POP DE
|
||||
RET
|
||||
|
||||
|
||||
i2c_stop_force:
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; i2c_rdy
|
||||
;
|
||||
; Waits until the PCF8584 signals a byte transmission/reception is complete.
|
||||
;------------------------------------------------------------------------------
|
||||
i2c_rdy:
|
||||
PUSH AF
|
||||
i2c_rlp:
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
BIT 7,A ; Is Tx/Rx complete? (S1 PIN=0?)
|
||||
call print_a_hex
|
||||
JR NZ,i2c_rlp ; No - loop
|
||||
i2crlpex:
|
||||
POP AF
|
||||
RET
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; i2c_bus_rdy
|
||||
;
|
||||
; Waits until the I2C bus is free before RETurning
|
||||
;------------------------------------------------------------------------------
|
||||
i2c_bus_rdy:
|
||||
PUSH AF
|
||||
i2c_blp:
|
||||
IN A,(CS_I2C_S1) ; Read byte from S1 register
|
||||
PUSH AF
|
||||
call print_a_hex
|
||||
POP AF
|
||||
BIT 0,A ; Is bus free? (S1 ~BB=1?)
|
||||
JR Z,i2c_blp ; No - loop
|
||||
i2cblpex:
|
||||
POP AF
|
||||
RET
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; PAUSE_LOOP
|
||||
;
|
||||
; Timer function
|
||||
;
|
||||
; 16-bit (BC) decrement counter, performing 4xNEG loop until BC
|
||||
; reaches zero.
|
||||
;
|
||||
; 61 T-states in loop = 15.25uS per loop @ 4 MHz - near enough
|
||||
; a second delay for 65,535 iterations.
|
||||
;
|
||||
; Set iteration count in BC before calling this function.
|
||||
; Destroys: BC
|
||||
;------------------------------------------------------------------------------
|
||||
PAUSE_LOOP:
|
||||
PUSH AF ; 11 T-states
|
||||
pau_lp:
|
||||
;NEG ; 8 T-states
|
||||
;NEG ; 8 T-states
|
||||
;NEG ; 8 T-states
|
||||
;NEG ; 8 T-states
|
||||
PUSH BC ; 11 T-states
|
||||
POP BC ; 10 T-states
|
||||
PUSH BC ; 11 T-states
|
||||
POP BC ; 10 T-states
|
||||
DEC BC ; 6 T-states
|
||||
LD A,C ; 9 T-states
|
||||
OR B ; 4 T-states
|
||||
JP NZ,pau_lp ; 10 T-states
|
||||
POP AF ; 10 T-states
|
||||
RET ; Pause complete, RETurn
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; PRINTINLINE
|
||||
;
|
||||
; String output function
|
||||
;
|
||||
; Prints in-line data (bytes immediately following the PRINTINLINE call)
|
||||
; until a string terminator is encountered (0 - null char).
|
||||
;------------------------------------------------------------------------------
|
||||
PRINTINLINE:
|
||||
EX (SP),HL ; PUSH HL and put RET ADDress into HL
|
||||
PUSH AF
|
||||
PUSH BC
|
||||
nxtILC:
|
||||
LD A,(HL)
|
||||
CP 0
|
||||
JR Z,endPrint
|
||||
CALL print_char
|
||||
INC HL
|
||||
JR nxtILC
|
||||
endPrint:
|
||||
INC HL ; Get past "null" terminator
|
||||
POP BC
|
||||
POP AF
|
||||
EX (SP),HL ; PUSH new RET ADDress on stack and restore HL
|
||||
RET
|
||||
|
||||
SlowAccess:
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
NOP
|
||||
RET
|
||||
|
||||
|
||||
;.include "regdump.s"
|
||||
|
||||
force_stop:
|
||||
IN A,(CS_I2C_S1)
|
||||
BIT 0, A
|
||||
RET NZ
|
||||
LD A, 11000011b
|
||||
OUT (CS_I2C_S1),A
|
||||
NOP
|
||||
NOP
|
||||
JR force_stop
|
||||
141
OperatingSystem/.unused/software/test_old.asm
Normal file
141
OperatingSystem/.unused/software/test_old.asm
Normal file
@@ -0,0 +1,141 @@
|
||||
.include "extern_symbols.s" ;include monitor symbols.
|
||||
org 0xB000
|
||||
;Testing code
|
||||
|
||||
;LD HL,MEM_IDE_BUFFER
|
||||
;LD B,32
|
||||
;call dump_pretty
|
||||
call find_partition
|
||||
;call fat_get_root_table
|
||||
;call fat_print_directory
|
||||
|
||||
call fat_get_root_table
|
||||
LD DE, [str1]
|
||||
CALL fat_lfs
|
||||
|
||||
JP PROMPT_BEGIN
|
||||
|
||||
str1:
|
||||
db "ILLUSION.PSG",0
|
||||
str2:
|
||||
db "HALLOWLT.TXT",0
|
||||
str3:
|
||||
db "TEST",0
|
||||
str4:
|
||||
db ".ORG",0
|
||||
|
||||
delay_small:
|
||||
PUSH AF
|
||||
POP AF
|
||||
PUSH AF
|
||||
POP AF
|
||||
RET
|
||||
|
||||
find_partition:
|
||||
;read bootsector
|
||||
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
|
||||
CALL ide_regwrite_8
|
||||
|
||||
LD A,0 ;read cylinder 0
|
||||
LD B,IDE_REG_LCYL
|
||||
CALL ide_regwrite_8
|
||||
LD A,0
|
||||
LD B,IDE_REG_HCYL
|
||||
CALL ide_regwrite_8
|
||||
|
||||
LD A,10100000b ;read head 0
|
||||
LD B,IDE_REG_HEAD
|
||||
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
|
||||
|
||||
LD B,4 ;Partition table length
|
||||
LD C,0 ;Partition ID counter
|
||||
LD IX,MEM_IDE_BUFFER+446 ;Load offest of first partition table entry
|
||||
find_partition_loop:
|
||||
LD A,(IX+4) ;load status byte
|
||||
OR A
|
||||
JP NZ, find_partition_process ;If not zero, jump to print function
|
||||
jp find_partition_next
|
||||
|
||||
find_partition_next:
|
||||
LD A,10 ;New line
|
||||
CALL print_char
|
||||
LD A,13
|
||||
CALL print_char
|
||||
LD DE,16
|
||||
ADD IX,DE
|
||||
DJNZ find_partition_loop
|
||||
RET
|
||||
|
||||
find_partition_process: ; process table entry
|
||||
ld hl, [str_part_seek_1]
|
||||
call print_str ;print
|
||||
LD A,(IX+0x04) ;load type
|
||||
call print_a_hex
|
||||
LD A,(IX+0x04) ;load type
|
||||
CP 0x0E
|
||||
JR NZ, find_partition_next
|
||||
|
||||
ld hl, [str_part_seek_2]
|
||||
call print_str ;print
|
||||
ld hl, [str_part_seek_3]
|
||||
call print_str ;print
|
||||
|
||||
LD A,(IX+0x08) ;load start LBA
|
||||
LD (MEM_IDE_PARTITION+3),A
|
||||
LD A,(IX+0x09) ;load start LBA
|
||||
LD (MEM_IDE_PARTITION+2),A
|
||||
LD A,(IX+0x0A) ;load start LBA
|
||||
LD (MEM_IDE_PARTITION+1),A
|
||||
LD A,(IX+0x0B) ;load start LBA
|
||||
LD (MEM_IDE_PARTITION+0),A
|
||||
|
||||
LD A,(MEM_IDE_PARTITION+3)
|
||||
call print_a_hex
|
||||
LD A,(MEM_IDE_PARTITION+2)
|
||||
call print_a_hex
|
||||
LD A,(MEM_IDE_PARTITION+1)
|
||||
call print_a_hex
|
||||
LD A,(MEM_IDE_PARTITION+0)
|
||||
call print_a_hex
|
||||
ld hl, [str_part_seek_4]
|
||||
call print_str ;print
|
||||
LD A,(IX+0x0C) ;load count LBA
|
||||
call print_a_hex
|
||||
LD A,(IX+0x0D) ;load count LBA
|
||||
call print_a_hex
|
||||
LD A,(IX+0x0E) ;load count LBA
|
||||
call print_a_hex
|
||||
LD A,(IX+0x0F) ;load count LBA
|
||||
call print_a_hex
|
||||
LD A,10 ;New line
|
||||
CALL print_char
|
||||
LD A,13
|
||||
CALL print_char
|
||||
RET
|
||||
|
||||
str_part_seek_1:
|
||||
db "- Type: 0x",0
|
||||
str_part_seek_2:
|
||||
db " State: ",0
|
||||
str_part_seek_3:
|
||||
db " LBA: 0x",0
|
||||
str_part_seek_4:
|
||||
db " Len: 0x",0
|
||||
str_sum:
|
||||
db "------------",10,13,0
|
||||
str_files:
|
||||
db " Files",10,13,0
|
||||
|
||||
.include "include/fat16.s"
|
||||
108
OperatingSystem/.unused/software/test_old2.asm
Normal file
108
OperatingSystem/.unused/software/test_old2.asm
Normal file
@@ -0,0 +1,108 @@
|
||||
.include "extern_symbols.s" ;include monitor symbols.
|
||||
org 0x6000
|
||||
|
||||
MEM_FAT_EXEC_CURR .equ var_scratch+10
|
||||
MEM_FAT_EXEC_COUNT .equ var_scratch+12
|
||||
MEM_FAT_EXEC_START .equ var_scratch+14
|
||||
|
||||
fat_exec:
|
||||
ld de,[var_input+6] ;prepare input like to mimic rom behaviour
|
||||
push de
|
||||
;DE has pointer to arguments
|
||||
call fat_openfile
|
||||
or a
|
||||
jp nz, _fat_exec_notfound ;if not found, abort
|
||||
;call fat_print_dbg
|
||||
;load header
|
||||
ld de, MEM_IDE_BUFFER
|
||||
call fat_readfilesec
|
||||
|
||||
|
||||
;ld hl, MEM_IDE_BUFFER ;print sector
|
||||
;ld b,0x20
|
||||
;call dump_pretty
|
||||
|
||||
ld a,(MEM_IDE_BUFFER)
|
||||
cp 0xC3
|
||||
jp nz, _fat_exec_notexec
|
||||
|
||||
call PRINTINLINE
|
||||
db 10,13,"Loading ",0
|
||||
ld hl,[var_input+6]
|
||||
call print_str
|
||||
call PRINTINLINE
|
||||
db " to 0x",0
|
||||
;get start address
|
||||
ld bc,(MEM_IDE_BUFFER + 10)
|
||||
ld a,b
|
||||
call print_a_hex
|
||||
ld a,c
|
||||
call print_a_hex
|
||||
call PRINTINLINE
|
||||
db " ... ",0
|
||||
;bc has start addr
|
||||
ld (MEM_FAT_EXEC_CURR),bc
|
||||
ld (MEM_FAT_EXEC_START),bc
|
||||
|
||||
;get amount of sectors to load
|
||||
ld hl,(MEM_IDE_BUFFER + 14)
|
||||
ld l,h
|
||||
srl l
|
||||
ld h,0 ;divide by 512
|
||||
inc hl ;increment because first sector is always loaded
|
||||
; hl contains sector count
|
||||
ld (MEM_FAT_EXEC_COUNT), hl
|
||||
|
||||
pop de ; restore filename
|
||||
call fat_openfile ;reset file information
|
||||
;start reading
|
||||
_fat_exec_readloop1:
|
||||
ld de,(MEM_FAT_EXEC_CURR)
|
||||
call fat_readfilesec
|
||||
ld hl,(MEM_FAT_EXEC_CURR)
|
||||
ld de,512
|
||||
add hl,de
|
||||
ld (MEM_FAT_EXEC_CURR),hl
|
||||
|
||||
ld hl,(MEM_FAT_EXEC_COUNT)
|
||||
dec hl
|
||||
ld (MEM_FAT_EXEC_COUNT),hl
|
||||
ld a,h
|
||||
or l
|
||||
jr z, _fat_exec_read_done
|
||||
jr _fat_exec_readloop1
|
||||
_fat_exec_read_done:
|
||||
call PRINTINLINE
|
||||
db "Load complete!",10,13,0
|
||||
ld hl,(MEM_FAT_EXEC_START)
|
||||
jp (hl)
|
||||
|
||||
|
||||
_fat_exec_notfound:
|
||||
call PRINTINLINE
|
||||
db 10,13,"File not found!",10,13,0
|
||||
ret
|
||||
|
||||
_fat_exec_notexec:
|
||||
call PRINTINLINE
|
||||
db 10,13,"File is not an executable!",10,13,0
|
||||
ret
|
||||
|
||||
|
||||
|
||||
_test_loop:
|
||||
call fat_readfilesec
|
||||
push af
|
||||
ld hl, MEM_IDE_BUFFER ;print sector
|
||||
ld b,0x20
|
||||
call dump_pretty
|
||||
;call PRINTINLINE
|
||||
;db 10,13,"SECREAD",10,13,0
|
||||
pop af
|
||||
or a
|
||||
jp z, _test_loop
|
||||
|
||||
;check if end of file
|
||||
|
||||
|
||||
ret
|
||||
BIN
OperatingSystem/.unused/software/zout/test.bin
Normal file
BIN
OperatingSystem/.unused/software/zout/test.bin
Normal file
Binary file not shown.
17
OperatingSystem/.unused/software/zout/test.hex
Normal file
17
OperatingSystem/.unused/software/zout/test.hex
Normal file
@@ -0,0 +1,17 @@
|
||||
:106000003EA7D3F13EADD3F1DBF0DBF1CB4720F877
|
||||
:106010003E6006FCCD5B603EAACD6160FE55202649
|
||||
:106020003EABCD6160B7201E3EAED3F1CD6E603E7B
|
||||
:10603000EED3F0CD6E60CD7560DBF0FEEE2815215D
|
||||
:10604000BA60CDE600C9219660CDE600C921DC60CA
|
||||
:10605000CDE600C9217B60CDE600C9D3F178D3F04D
|
||||
:10606000C9D3F1DBF1CD0E011F30F8DBF0C9DBF154
|
||||
:106070001F1F38FAC9DBF11F30FBC950532F3220E4
|
||||
:106080004B6579626F61726420696E697469616CD5
|
||||
:10609000697A65642E0050532F3220436F6E7472FC
|
||||
:1060A0006F6C6C6572206572726F72212053797308
|
||||
:1060B00074656D2048414C54210050532F32204BC1
|
||||
:1060C0006579626F617264206572726F722120530C
|
||||
:1060D000797374656D2048414C54210050532F3220
|
||||
:1060E000206E6F206B6579626F61726420666F75D8
|
||||
:0460F0006E642100B9
|
||||
:00000001FF
|
||||
1289
OperatingSystem/.unused/software/zout/test.lst
Normal file
1289
OperatingSystem/.unused/software/zout/test.lst
Normal file
File diff suppressed because it is too large
Load Diff
16
OperatingSystem/.unused/software/zout/test.mon
Normal file
16
OperatingSystem/.unused/software/zout/test.mon
Normal file
@@ -0,0 +1,16 @@
|
||||
!6000 3E A7 D3 F1 3E AD D3 F1 DB F0 DB F1 CB 47 20 F8
|
||||
!6010 3E 60 06 FC CD 5B 60 3E AA CD 61 60 FE 55 20 26
|
||||
!6020 3E AB CD 61 60 B7 20 1E 3E AE D3 F1 CD 6E 60 3E
|
||||
!6030 EE D3 F0 CD 6E 60 CD 75 60 DB F0 FE EE 28 15 21
|
||||
!6040 BA 60 CD E6 00 C9 21 96 60 CD E6 00 C9 21 DC 60
|
||||
!6050 CD E6 00 C9 21 7B 60 CD E6 00 C9 D3 F1 78 D3 F0
|
||||
!6060 C9 D3 F1 DB F1 CD 0E 01 1F 30 F8 DB F0 C9 DB F1
|
||||
!6070 1F 1F 38 FA C9 DB F1 1F 30 FB C9 50 53 2F 32 20
|
||||
!6080 4B 65 79 62 6F 61 72 64 20 69 6E 69 74 69 61 6C
|
||||
!6090 69 7A 65 64 2E 00 50 53 2F 32 20 43 6F 6E 74 72
|
||||
!60A0 6F 6C 6C 65 72 20 65 72 72 6F 72 21 20 53 79 73
|
||||
!60B0 74 65 6D 20 48 41 4C 54 21 00 50 53 2F 32 20 4B
|
||||
!60C0 65 79 62 6F 61 72 64 20 65 72 72 6F 72 21 20 53
|
||||
!60D0 79 73 74 65 6D 20 48 41 4C 54 21 00 50 53 2F 32
|
||||
!60E0 20 6E 6F 20 6B 65 79 62 6F 61 72 64 20 66 6F 75
|
||||
!60F0 6E 64 21 00
|
||||
Reference in New Issue
Block a user