-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: [atari] fgetpos/fsetpos using NOTE/POINT #355
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
; Copyright 2024 LLVM-MOS Project | ||
; Licensed under the Apache License, Version 2.0 with LLVM Exceptions. | ||
; See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license | ||
; information. | ||
|
||
; char __note (int fd, fpos_t *pos); | ||
|
||
.include "atari.inc" | ||
.include "imag.inc" | ||
|
||
.globl __note | ||
|
||
__note: | ||
jsr fdtoiocb | ||
bmi error | ||
tax | ||
lda #NOTE | ||
sta ICCOM,x | ||
jsr CIOV | ||
bmi error | ||
ldy #0 | ||
lda ICAX5,x | ||
sta (__rc2),y | ||
iny | ||
lda ICAX3,x | ||
sta (__rc2),y | ||
iny | ||
lda ICAX4,x | ||
sta (__rc2),y | ||
iny | ||
lda #0 | ||
sta (__rc2),y | ||
rts | ||
|
||
error: | ||
ldy #3 | ||
lda #$ff | ||
store_error: | ||
sta (__rc2),y | ||
dey | ||
bpl store_error | ||
rts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
; Copyright 2024 LLVM-MOS Project | ||
; Licensed under the Apache License, Version 2.0 with LLVM Exceptions. | ||
; See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license | ||
; information. | ||
|
||
; char __point (int fd, const fpos_t *pos); | ||
|
||
.include "atari.inc" | ||
.include "imag.inc" | ||
|
||
.globl __point | ||
|
||
__point: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
jsr fdtoiocb | ||
bmi invalid | ||
tax | ||
ldy #3 | ||
lda (__rc2),y | ||
bne invalid | ||
lda #POINT | ||
sta ICCOM,x | ||
dey | ||
lda (__rc2),y | ||
sta ICAX4,x | ||
dey | ||
lda (__rc2),y | ||
sta ICAX3,x | ||
dey | ||
lda (__rc2),y | ||
sta ICAX5,x | ||
jsr CIOV | ||
bmi cioerr | ||
lda #0 | ||
rts | ||
|
||
invalid: | ||
lda #<EINVAL | ||
jmp __directerrno | ||
|
||
cioerr: | ||
tya | ||
jmp __mappederrno |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <stdio.h> | ||
#include <__stdio-internal.h> | ||
|
||
char __note(int fd, fpos_t *pos); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Annotate function with |
||
|
||
void __update_diskpos(FILE *stream) { | ||
__note(stream->handle, &stream->diskpos); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,13 @@ | |
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <limits.h> | ||
#include <stdbool.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do already have |
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#include <__stdio-internal.h> | ||
|
||
// Flags for representing mode (see fopen()). Note these must fit the same | ||
// status field as the _IO?BF flags in <stdio.h> and the internal flags below. | ||
#define FREAD (1u << 3) | ||
|
@@ -37,20 +38,6 @@ | |
// File associated with stream should be remove()d on closing (tmpfile()). | ||
#define DELONCLOSE (1u << 14) | ||
|
||
struct _FILE { | ||
signed char handle; // OS file handle | ||
char *buffer; // Pointer to buffer memory | ||
size_t bufsize; // Size of buffer | ||
size_t bufidx; // Index of current position in buffer | ||
size_t bufend; // Index of last pre-read character in buffer | ||
fpos_t pos; // Offset and multibyte parsing state | ||
char ungetc_buf; // ungetc() buffer | ||
bool ungetc_buf_full; // Number of ungetc()'ed characters | ||
unsigned status; // Status flags; see above | ||
char *filename; // Name the current stream has been opened with | ||
FILE *next; // Pointer to next struct (internal) | ||
}; | ||
|
||
// Buffer one-two lines; write() implementations have constant overhead, and | ||
// buffering amortizes it. | ||
static char serr_buf[80]; | ||
|
@@ -130,6 +117,9 @@ static unsigned filemode(const char *const mode) { | |
return rc; | ||
} | ||
|
||
__attribute__((weak)) void __update_diskpos(FILE *stream) { | ||
} | ||
|
||
static FILE *init_file(FILE *stream) { | ||
FILE *rc = stream; | ||
|
||
|
@@ -563,6 +553,8 @@ static int prep_read(FILE *stream) { | |
} | ||
|
||
static int fill_buffer(FILE *stream) { | ||
__update_diskpos(stream); | ||
|
||
/* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */ | ||
int rc = read(stream->handle, stream->buffer, stream->bufsize); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef __STDIO_INTERNAL_H_ | ||
#define __STDIO_INTERNAL_H_ | ||
|
||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
struct _FILE { | ||
signed char handle; // OS file handle | ||
char *buffer; // Pointer to buffer memory | ||
size_t bufsize; // Size of buffer | ||
size_t bufidx; // Index of current position in buffer | ||
size_t bufend; // Index of last pre-read character in buffer | ||
fpos_t pos; // Offset and multibyte parsing state | ||
char ungetc_buf; // ungetc() buffer | ||
bool ungetc_buf_full; // Number of ungetc()'ed characters | ||
unsigned status; // Status flags; see above | ||
char *filename; // Name the current stream has been opened with | ||
fpos_t diskpos; // Atari NOTE position | ||
FILE *next; // Pointer to next struct (internal) | ||
}; | ||
|
||
void __update_diskpos(FILE *stream); | ||
|
||
#endif // __STDIO_INTERNAL_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
.section .text.__note,"ax",@progbits