-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2352: Add port headers + seeking
- Loading branch information
Showing
6 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
#ifndef __AQPLUS_H | ||
#define __AQPLUS_H | ||
|
||
#include <arch/aquarius.h> | ||
|
||
// Stat buffer returned by ESP32 | ||
struct aqplus_stat { | ||
uint16_t date; | ||
uint16_t time; | ||
uint8_t attr; | ||
uint32_t size; | ||
}; | ||
|
||
|
||
static __sfr __at 0xE0 IO_VCTRL; | ||
static __sfr __at 0xE1 IO_VSCRX_L; | ||
static __sfr __at 0xE2 IO_VSCRX_H; | ||
static __sfr __at 0xE3 IO_VSCRY; | ||
static __sfr __at 0xE4 IO_VSPRSEL; | ||
static __sfr __at 0xE5 IO_VSPRX_L; | ||
static __sfr __at 0xE6 IO_VSPRX_H; | ||
static __sfr __at 0xE7 IO_VSPRY; | ||
static __sfr __at 0xE8 IO_VSPRIDX; | ||
static __sfr __at 0xE9 IO_VSPRATTR; | ||
static __sfr __at 0xEA IO_VPALSEL; | ||
static __sfr __at 0xEB IO_VPALDATA; | ||
static __sfr __at 0xEC IO_VLINE; | ||
static __sfr __at 0xED IO_VIRQLINE; | ||
static __sfr __at 0xEE IO_IRQMASK; | ||
static __sfr __at 0xEF IO_IRQSTAT; | ||
static __sfr __at 0xF0 IO_BANK0; | ||
static __sfr __at 0xF1 IO_BANK1; | ||
static __sfr __at 0xF2 IO_BANK2; | ||
static __sfr __at 0xF3 IO_BANK3; | ||
static __sfr __at 0xF4 IO_ESPCTRL; | ||
static __sfr __at 0xF5 IO_ESPDATA; | ||
static __sfr __at 0xF8 IO_PSG2DATA; | ||
static __sfr __at 0xF9 IO_PSG2ADDR; | ||
static __sfr __at 0xFB IO_SYSCTRL; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
|
||
#include <stdio.h> | ||
|
||
|
||
int fdgetpos(int fd, fpos_t *dump) | ||
{ | ||
#asm | ||
INCLUDE "fcntl.def" | ||
EXTERN asm_strlen | ||
|
||
ld a,ESPCMD_TELL | ||
call __esp_send_cmd | ||
ld hl,sp+4 | ||
ld a,(hl) ;fd | ||
call __esp_send_byte | ||
call __esp_read_byte | ||
and a | ||
jr z,continue | ||
ld hl,-1 | ||
ret | ||
continue: | ||
ld hl,sp+2 | ||
ld a,(hl) | ||
inc hl | ||
ld h,(hl) | ||
call __esp_read_byte | ||
ld (hl),a | ||
call __esp_read_byte | ||
ld (hl),a | ||
call __esp_read_byte | ||
ld (hl),a | ||
call __esp_read_byte | ||
ld (hl),a | ||
ld hl,0 | ||
ret | ||
#endasm | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
|
||
#include <stdio.h> | ||
|
||
|
||
long fdtell(int fd) __naked | ||
{ | ||
#asm | ||
INCLUDE "fcntl.def" | ||
EXTERN asm_strlen | ||
|
||
ld a,ESPCMD_TELL | ||
call __esp_send_cmd | ||
ld hl,2 | ||
add hl,sp | ||
ld a,(hl) ;fd | ||
call __esp_send_byte | ||
call __esp_read_byte | ||
and a | ||
jr z,continue | ||
ld hl,-1 | ||
ld de,hl | ||
ret | ||
continue: | ||
call __esp_read_byte | ||
ld l,a | ||
call __esp_read_byte | ||
ld h,a | ||
call __esp_read_byte | ||
ld e,a | ||
call __esp_read_byte | ||
ld d,a | ||
ret | ||
#endasm | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include <fcntl.h> | ||
#include <stdio.h> | ||
|
||
|
||
static int aq_seek(int fd, long posn) __smallc __naked | ||
{ | ||
#asm | ||
INCLUDE "fcntl.def" | ||
ld a,ESPCMD_SEEK | ||
call __esp_send_cmd | ||
ld hl,sp+6 | ||
ld a,(hl) | ||
call __esp_send_byte | ||
ld hl,sp+2 | ||
ld bc,4 | ||
call __esp_send_bytes | ||
call __esp_read_byte | ||
ld l,a | ||
ld h,0 | ||
ret | ||
#endasm | ||
} | ||
|
||
|
||
|
||
long lseek(int fd,long posn, int whence) __smallc | ||
{ | ||
switch ( (uint8_t)whence ) { | ||
case SEEK_SET: | ||
break; | ||
case SEEK_CUR: | ||
posn += fdtell(fd); | ||
break; | ||
case SEEK_END: | ||
return -1; // Not supported | ||
break; | ||
} | ||
|
||
if (aq_seek(fd, posn) == 0 ) { | ||
return fdtell(fd); | ||
} | ||
return -1L; | ||
} |