Skip to content

Commit

Permalink
Issue #2352: Add port headers + seeking
Browse files Browse the repository at this point in the history
  • Loading branch information
suborb committed Jul 17, 2023
1 parent f74878e commit b138d68
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 1 deletion.
42 changes: 42 additions & 0 deletions include/arch/aqplus.h
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
23 changes: 22 additions & 1 deletion include/arch/aquarius.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <sys/types.h>
#include <sound.h>

#ifdef __AQUARIUSPLUS__
#include <arch/aqplus.h>
#endif

////////////
// TAPE I/O
Expand All @@ -24,7 +27,25 @@ extern int __LIB__ tape_load_block_callee(void *addr, size_t len, unsigned cha

#define tape_load_block(a,b,c) tape_load_block_callee(a,b,c)


// IO port definitions
static __sfr __at 0xF6 IO_PSG1DATA;
static __sfr __at 0xF7 IO_PSG1ADDR;
static __sfr __at 0xFC IO_CASSETTE;
static __sfr __at 0xFD IO_CPM;
static __sfr __at 0xFD IO_VSYNC;
static __sfr __at 0xFE IO_PRINTER;
static __sfr __at 0xFF IO_SCRAMBLE;


static __sfr __at 0x00FF IO_KEYBOARD_ALL;
static __sfr __at 0x7FFF IO_KEYBOARD_COL7;
static __sfr __at 0xBFFF IO_KEYBOARD_COL6;
static __sfr __at 0xDFFF IO_KEYBOARD_COL5;
static __sfr __at 0xEFFF IO_KEYBOARD_COL4;
static __sfr __at 0xF7FF IO_KEYBOARD_COL3;
static __sfr __at 0xFBFF IO_KEYBOARD_COL2;
static __sfr __at 0xFDFF IO_KEYBOARD_COL1;
static __sfr __at 0xFEFF IO_KEYBOARD_COL0;


#endif
3 changes: 3 additions & 0 deletions libsrc/target/aquarius/aquarius.lst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ target/aquarius/tape/tape_load_block_callee
target/aquarius/fcntl/chdir
target/aquarius/fcntl/close
target/aquarius/fcntl/esp
target/aquarius/fcntl/fdgetpos
target/aquarius/fcntl/fdtell
target/aquarius/fcntl/lseek
target/aquarius/fcntl/mkdir
target/aquarius/fcntl/open
target/aquarius/fcntl/read
Expand Down
38 changes: 38 additions & 0 deletions libsrc/target/aquarius/fcntl/fdgetpos.c
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
}
35 changes: 35 additions & 0 deletions libsrc/target/aquarius/fcntl/fdtell.c
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
}
44 changes: 44 additions & 0 deletions libsrc/target/aquarius/fcntl/lseek.c
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;
}

0 comments on commit b138d68

Please sign in to comment.