diff --git a/doc/mastodon-user-guide.odt b/doc/mastodon-user-guide.odt index a45dadfc..edb2c561 100644 Binary files a/doc/mastodon-user-guide.odt and b/doc/mastodon-user-guide.odt differ diff --git a/src/image-viewer/Makefile b/src/image-viewer/Makefile index 3f0c96d8..b57b261a 100644 --- a/src/image-viewer/Makefile +++ b/src/image-viewer/Makefile @@ -25,7 +25,6 @@ imgview_SOURCES := \ imageview.c \ ../lib/file_select.c \ ../lib/progress_bar.c \ - ../lib/hgr.c \ ../lib/hgr_addrs.c \ ../lib/realloc_safe.c \ @@ -38,6 +37,7 @@ imgview_CC65SOURCES := \ ../lib/asm/path_helper.s \ ../lib/asm/clrzone.s \ ../lib/asm/malloc0.s \ + ../lib/asm/hgr.s \ ../lib/dputc.s \ ../lib/scroll.s \ ../lib/FVTABZ.s \ @@ -53,6 +53,7 @@ imgview_GCCSOURCES := \ ../lib/c/path_helper.c \ ../lib/c/clrzone.c \ ../lib/c/malloc0.c \ + ../lib/c/hgr.c \ ../lib/tgi_sdl.c \ ../lib/tgi_fastline.c \ ../lib/strtrim.c diff --git a/src/lib/asm/hgr.s b/src/lib/asm/hgr.s new file mode 100644 index 00000000..e68dd43c --- /dev/null +++ b/src/lib/asm/hgr.s @@ -0,0 +1,85 @@ +; +; Copyright (C) 2022-2024 Colin Leroy-Mira +; +; This program is free software; you can redistribute it and/or modify +; it under the terms of the GNU General Public License as published by +; the Free Software Foundation; either version 3 of the License, or +; (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this program. If not, see . +; + .export _init_hgr + .export _init_text + .export _hgr_mixon + .export _hgr_mixoff + .export _hgr_init_done + .export _hgr_mix_is_on + + .data + +_hgr_init_done: .byte 0 +_hgr_mix_is_on: .byte 0 + + .segment "LOWCODE" + +_init_hgr: + .ifdef IIGS + cmp #$00 + bne @color_set + + lda #$80 + sta $C021 ; MONOCOLOR + lda $C029 ; NEWVIDEO + ora #$20 ; set bit 5 + sta $C029 + bne @color_set + + lda #$00 + sta $C021 ; MONOCOLOR + lda $C029 ; NEWVIDEO + and #$DF ; clear bit 5 + sta $C029 + .endif +@color_set: + + lda #$20 + sta $E6 ; HGRPAGE + + ; Set HGR mode + bit $C000 ; 80STORE + bit $C050 ; TXTCLR + bit $C052 ; MIXCLR + bit $C057 ; HIRES + bit $C054 ; LOWSCR + + ldx #1 + stx _hgr_init_done + dex + stx _hgr_mix_is_on + rts + +_init_text: + bit $C054 ; LOWSCR + bit $C051 ; TXTSET + bit $C056 ; LORES + lda #0 + sta _hgr_init_done + rts + +_hgr_mixon: + bit $C053 + lda #1 + sta _hgr_mix_is_on + rts + +_hgr_mixoff: + bit $C052 + lda #0 + sta _hgr_mix_is_on + rts diff --git a/src/lib/c/hgr.c b/src/lib/c/hgr.c new file mode 100644 index 00000000..084bbc2a --- /dev/null +++ b/src/lib/c/hgr.c @@ -0,0 +1,16 @@ +#include "hgr.h" + +char hgr_init_done = 0; +char hgr_mix_is_on = 0; + +#ifndef __CC65__ +#include "tgi_compat.h" + +void init_hgr(uint8 mono) { + tgi_init(); +} +void init_text(void) { + tgi_done(); +} + +#endif diff --git a/src/lib/hgr.c b/src/lib/hgr.c deleted file mode 100644 index 80a15863..00000000 --- a/src/lib/hgr.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "hgr.h" - -char hgr_init_done = 0; -char hgr_mix_is_on = 0; - -#pragma code-name(push, "LOWCODE") - -#ifndef __CC65__ -#include "tgi_compat.h" - -void init_hgr(uint8 mono) { - tgi_init(); -} -void init_text(void) { - tgi_done(); -} - -#else - -void init_hgr(uint8 mono) { -#ifdef __APPLE2__ - -#ifdef IIGS - if (mono) { - __asm__("lda #$80"); - __asm__("sta $C021"); /* MONOCOLOR */ - - __asm__("lda $C029"); /* NEWVIDEO */ - __asm__("ora #$20"); /* Set bit 5 */ - __asm__("sta $C029"); - - } else { - __asm__("lda #$00"); - __asm__("sta $C021"); /* MONOCOLOR */ - - __asm__("lda $C029"); /* NEWVIDEO */ - __asm__("and #$DF"); /* Clear bit 5 */ - __asm__("sta $C029"); - } -#endif - - #ifdef USE_HGR2 - __asm__("lda #$40"); - #else - __asm__("lda #$20"); - #endif - /* Set draw page */ - __asm__("sta $E6"); /* HGRPAGE */ - - /* Set graphics mode */ - __asm__("bit $C000"); /* 80STORE */ - __asm__("bit $C050"); /* TXTCLR */ - __asm__("bit $C052"); /* MIXCLR */ - __asm__("bit $C057"); /* HIRES */ - - /* Set view page */ - #ifdef USE_HGR2 - __asm__("bit $C055"); /* HISCR */ - #else - __asm__("bit $C054"); /* LOWSCR */ - #endif -#endif - hgr_init_done = 1; -} - -void init_text(void) { -#ifdef __APPLE2__ - switch_text(); -#endif - hgr_init_done = 0; -} -#endif - -#pragma code-name(pop) diff --git a/src/lib/hgr.h b/src/lib/hgr.h index 7f1b547d..7932e61c 100644 --- a/src/lib/hgr.h +++ b/src/lib/hgr.h @@ -7,30 +7,21 @@ #define HGR_WIDTH 280U #define HGR_HEIGHT 192U +void __fastcall__ init_hgr(uint8 mono); +void __fastcall__ init_text(void); +extern char hgr_mix_is_on; +extern char hgr_init_done; + #ifdef __CC65__ #define HGR_PAGE 0x2000 #define HGR_PAGE2 0x4000 -#else -extern char HGR_PAGE[HGR_LEN]; -#endif -extern char hgr_init_done; -extern char hgr_mix_is_on; -void init_hgr(uint8 mono); -void init_text(void); - -#ifdef __CC65__ -#define hgr_mixon() do { __asm__("bit $C053"); hgr_mix_is_on = 1; } while (0) -#define hgr_mixoff() do { __asm__("bit $C052"); hgr_mix_is_on = 0; } while (0) -#define switch_text() do { \ - __asm__("bit $C054"); /* LOWSCR */ \ - __asm__("bit $C051"); /* TXTSET */ \ - __asm__("bit $C056"); /* LORES */ \ -} while (0) -#define hgr_mix_is_on() hgr_mix_is_on +void __fastcall__ hgr_mixon(void); +void __fastcall__ hgr_mixoff(void); #else +extern char HGR_PAGE[HGR_LEN]; #define hgr_mixon() #define hgr_mixoff() -#define hgr_mix_is_on() 0 #endif + #endif diff --git a/src/lib/surl.h b/src/lib/surl.h index bb9db209..cddb406e 100644 --- a/src/lib/surl.h +++ b/src/lib/surl.h @@ -61,7 +61,8 @@ int __fastcall__ surl_get_json(char *buffer, const char *selector, const char *t int surl_wait_for_stream(void); int __fastcall__ surl_stream_video(void); int __fastcall__ surl_stream_audio(char numcols, char title_y, char vu_x, char vu_y); -int __fastcall__ surl_stream_av(void); +int __fastcall__ surl_stream_av(char *subtitles_url, char *url); + void __fastcall__ simple_serial_dump(char id, char *ptr, int nmemb); #else #define surl_stream_video() diff --git a/src/lib/surl/surl_stream_av/6502.s b/src/lib/surl/surl_stream_av/6502.s index e6bf7af4..eb464bf5 100644 --- a/src/lib/surl/surl_stream_av/6502.s +++ b/src/lib/surl/surl_stream_av/6502.s @@ -125,6 +125,9 @@ next = _zp10 ; word - next cycle JUMP_NEXT_DUTY ; 9 jump to next duty cycle .endmacro + .bss +got_art: .res 1 + .segment "CODE" ; Align each duty cycle function @@ -139,18 +142,31 @@ SAMPLE_MULT = 1 .align $100 .assert * = _SAMPLES_BASE + $100, error .include "duty-cycles/1.s" +; Add some setup function to fill in the gaps +.include "update_load_progress.s" +.include "surl_stream_av_send_request.s" +.include "surl_stream_av_setup_ui.s" +.include "surl_stream_av_get_art.s" .align $100 .assert * = _SAMPLES_BASE + $200, error .include "duty-cycles/2.s" +; Add some setup function to fill in the gaps +.include "surl_stream_av_prepare_start.s" +.include "surl_stream_av_handle_preload.s" +.include "surl_stream_av.s" .align $100 .assert * = _SAMPLES_BASE + $300, error .include "duty-cycles/3.s" +; Add some strings to fill in the gaps +.include "strings-a.inc" .align $100 .assert * = _SAMPLES_BASE + $400, error .include "duty-cycles/4.s" +; Add some strings to fill in the gaps +.include "strings-b.inc" .align $100 .assert * = _SAMPLES_BASE + $500, error @@ -258,7 +274,7 @@ SAMPLE_MULT = 1 .include "duty-cycles/26.s" ; Stuff code between duty cycles to optimize size -.include "surl_stream_av.s" +.include "surl_start_stream_av.s" .include "calc_bases.s" .include "calc_text_bases.s" .include "../surl_stream_common/patch_addresses.s" diff --git a/src/lib/surl/surl_stream_av/65c02.s b/src/lib/surl/surl_stream_av/65c02.s index 11298eb3..27dcb9b8 100644 --- a/src/lib/surl/surl_stream_av/65c02.s +++ b/src/lib/surl/surl_stream_av/65c02.s @@ -81,7 +81,6 @@ .include "constants.inc" .include "zp-variables.inc" .include "cycle-wasters.inc" - ; ----------------------------------------------------------------------------- ; CPU-specific constant and macros @@ -112,6 +111,10 @@ SAMPLE_MULT = 2 JUMP_NEXT_DUTY ; 9 jump to next duty cycle .endmacro + .bss + +got_art: .res 1 + .segment "CODE" ; The AVCODE segment location is non-important (apart of course it must not be @@ -190,7 +193,7 @@ _SAMPLES_BASE = * ; The rest of the functions don't need to be aligned. -.include "surl_stream_av.s" +.include "surl_start_stream_av.s" .include "../surl_stream_common/patch_addresses.s" .include "../surl_stream_common/patch_audio_registers.s" .include "patch_video_registers.s" @@ -199,7 +202,17 @@ _SAMPLES_BASE = * .include "video-data-data.inc" .include "audio-data.inc" +; Setup functions .include "setup.s" +.include "strings-a.inc" +.include "strings-b.inc" +.include "update_load_progress.s" +.include "surl_stream_av_send_request.s" +.include "surl_stream_av_setup_ui.s" +.include "surl_stream_av_get_art.s" +.include "surl_stream_av_prepare_start.s" +.include "surl_stream_av_handle_preload.s" +.include "surl_stream_av.s" ; ----------------------------------------------------------------------------- ; CPU-specific data (duty cycles handlers table) diff --git a/src/lib/surl/surl_stream_av/constants.inc b/src/lib/surl/surl_stream_av/constants.inc index 46e86ba4..2a4fdd88 100644 --- a/src/lib/surl/surl_stream_av/constants.inc +++ b/src/lib/surl/surl_stream_av/constants.inc @@ -20,3 +20,6 @@ PAGE1_HB = PAGE0_HB .endif SPKR := $C030 + +VIDEOMODE_40COL = $11 +VIDEOMODE_80COL = $12 diff --git a/src/lib/surl/surl_stream_av/imports.inc b/src/lib/surl/surl_stream_av/imports.inc index ca33f156..bcad5302 100644 --- a/src/lib/surl/surl_stream_av/imports.inc +++ b/src/lib/surl/surl_stream_av/imports.inc @@ -1,3 +1,4 @@ + .export _surl_start_stream_av .export _surl_stream_av .export _SAMPLES_BASE @@ -8,14 +9,36 @@ .import _simple_serial_get_cmd_reg .import _simple_serial_get_ctrl_reg + .import _enable_subtitles + .import _video_size + .import _translit_charset + .import _scrh + .import _hgr_mixon, _hgr_mixoff + .import _hgr_mix_is_on + .import _serial_putc_direct + .import _simple_serial_getc + .import _simple_serial_puts_nl .import _serial_read_byte_no_irq .import _simple_serial_set_irq .import _simple_serial_flush - .import _sleep, _init_text, _clrscr + + .import _surl_start_request + .import _surl_read_with_barrier + .import _ser_params .import acia_status_reg_r, acia_data_reg_r + .import _init_text, _init_hgr, _set_scrollwindow + .import _gotoxy, _cprintf, _videomode, _clrscr + .import _bzero, _memset, _sleep, _cputs + .import pusha, pusha0, push0, pushax, shlax3, popptr1 + + .importzp ptr1 + .include "apple2.inc" .include "../../simple_serial.inc" + .include "../../../surl-server/surl_protocol.inc" + .include "../../surl.inc" + .include "stdio.inc" diff --git a/src/lib/surl/surl_stream_av/stream_url.c b/src/lib/surl/surl_stream_av/stream_url.c deleted file mode 100644 index 6d3c2c14..00000000 --- a/src/lib/surl/surl_stream_av/stream_url.c +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "hgr.h" -#include "simple_serial.h" -#include "path_helper.h" -#include "surl.h" -#include "scrollwindow.h" - -#pragma code-name (push, STREAM_URL_SEGMENT) - -extern char enable_subtitles; -extern char video_size; -extern char *translit_charset; -extern unsigned char scrh; - -static void update_progress(void) { - unsigned char eta; - - simple_serial_putc(SURL_CLIENT_READY); - eta = simple_serial_getc(); - hgr_mixon(); - gotoxy(11, 0); /* strlen("Loading...") + 1 */ - if (eta == 255) - cputs("(Opening stream...)"); - else if (eta == 254) - cputs("(More than 30m remaining)"); - else - cprintf("(About %ds remaining) ", eta*8); -} - -int stream_url(char *url, char *subtitles_url) { - char r, got_art = 0; - - surl_start_request(NULL, 0, url, SURL_METHOD_STREAM_AV); - - simple_serial_puts_nl(translit_charset); - simple_serial_putc(1); /* Monochrome */ - if (enable_subtitles) { - simple_serial_putc(subtitles_url != NULL ? SUBTITLES_URL : SUBTITLES_AUTO); /* Enable subtitles */ - if (subtitles_url != NULL) { - simple_serial_puts(subtitles_url); - simple_serial_putc('\n'); - } - } else { - simple_serial_putc(SUBTITLES_NO); - } - - /* Do all of the slow things before finishing to send STREAM_AV parameters, - * otherwise proxy's going to start sending _STREAM_LOAD ETAs before we can - * answer. - */ - clrscr(); - set_scrollwindow(20, scrh); - init_hgr(1); - hgr_mixon(); - gotoxy(0, 0); - - /* clear text page 2 */ - memset((char*)0x800, ' '|0x80, 0x400); - -#ifdef __APPLE2ENH__ - cputs("Loading...\r\n" - "Controls: Space: Play/Pause, Esc: Quit player,\r\n" - " Left/Right: Rewind/Forward 10s, Up/Down: Rewind/Forward 1m\r\n" - " -/=/+: Volume up/default/down S: Toggle speed/quality"); -#else - cputs("Loading...\r\n" - "Space: play/pause, Esc: Quit player,\r\n" - "Left/right: Rew/Fwd 10s, U/J: 60s\r\n" - "-/=/+: Vol up/def/down, S: spd/quality "); -#endif - - /* Ready, send last parameter */ - simple_serial_putc(video_size); - -wait_load: - r = simple_serial_getc(); - if (r == SURL_ANSWER_STREAM_LOAD) { - update_progress(); - if (kbhit() && cgetc() == CH_ESC) - simple_serial_putc(SURL_METHOD_ABORT); - else - simple_serial_putc(SURL_CLIENT_READY); - goto wait_load; - } else if (r == SURL_ANSWER_STREAM_ART) { - surl_read_with_barrier((char *)HGR_PAGE, HGR_LEN); - got_art = 1; - simple_serial_putc(SURL_CLIENT_READY); - goto wait_load; - } else if (r == SURL_ANSWER_STREAM_START) { - simple_serial_putc(SURL_CLIENT_READY); - if (simple_serial_getc() == SURL_VIDEO_PORT_NOK) { - clrscr(); - cputs("Warning: proxy couldn't open video aux_tty.\r\nNo video available."); - sleep(5); - } - if (!got_art) { - bzero((char *)HGR_PAGE, HGR_LEN); - } -#ifdef __APPLE2ENH__ - videomode(VIDEOMODE_40COL); -#endif - hgr_mixoff(); - set_scrollwindow(0, scrh); - clrscr(); - surl_stream_av(); -#ifdef __APPLE2ENH__ - videomode(VIDEOMODE_80COL); -#endif - } else { - clrscr(); - cputs("Playback error"); - sleep(1); - } - set_scrollwindow(0, scrh); - return 0; -} -#pragma code-name (pop) diff --git a/src/lib/surl/surl_stream_av/stream_url.h b/src/lib/surl/surl_stream_av/stream_url.h deleted file mode 100644 index cd17f9da..00000000 --- a/src/lib/surl/surl_stream_av/stream_url.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __stream_url__h -#define __stream_url__h - -int stream_url(char *url, char *subtitles_url); - -#endif diff --git a/src/lib/surl/surl_stream_av/strings-a.inc b/src/lib/surl/surl_stream_av/strings-a.inc new file mode 100644 index 00000000..028f9bbf --- /dev/null +++ b/src/lib/surl/surl_stream_av/strings-a.inc @@ -0,0 +1,14 @@ + +eta_open_str: .asciiz "(Opening stream...)" +eta_long_str: .asciiz "(More than 30m remaining)" +eta_secs_str: .asciiz "(About %ds remaining) " +playback_err_str: .asciiz "Playback error" + +.ifdef __APPLE2ENH__ +no_video_str: .byte "Warning: proxy couldn't open video aux_tty.",$0D,$0A + .byte "No video available.", $00 + +.else +no_video_str: .byte "Warning: proxy can't open video aux_tty",$0D,$0A + .byte "No video available.", $00 +.endif diff --git a/src/lib/surl/surl_stream_av/strings-b.inc b/src/lib/surl/surl_stream_av/strings-b.inc new file mode 100644 index 00000000..9523de96 --- /dev/null +++ b/src/lib/surl/surl_stream_av/strings-b.inc @@ -0,0 +1,11 @@ +.ifdef __APPLE2ENH__ +controls_str: .byte "Loading...",$0D,$0A + .byte "Controls: Space: Play/Pause, Esc: Quit player,",$0D,$0A + .byte " Left/Right: Rewind/Forward 10s, Up/Down: Rewind/Forward 1m",$0D,$0A + .byte " -/=/+: Volume up/default/down S: Toggle speed/quality",$00 +.else +controls_str: .byte "Loading...",$0D,$0A + .byte "Space: play/pause, Esc: Quit player,",$0D,$0A + .byte "Left/right: Rew/Fwd 10s, U/J: 60s",$0D,$0A + .byte "-/=/+: Vol up/def/down, S: spd/quality",$00 +.endif diff --git a/src/lib/surl/surl_stream_av/surl_start_stream_av.s b/src/lib/surl/surl_stream_av/surl_start_stream_av.s new file mode 100644 index 00000000..36bfe7b7 --- /dev/null +++ b/src/lib/surl/surl_stream_av/surl_start_stream_av.s @@ -0,0 +1,32 @@ +_surl_start_stream_av: ; Entry point + php + sei ; Disable all interrupts + + pha + + lda #$00 ; Disable serial interrupts + jsr _simple_serial_set_irq + + pla + ; Setup pointers + jsr setup + + .ifdef DOUBLE_BUFFER + ; Clear HGR page 2 (page 1 must be done by caller) + bit $C082 + lda #$40 + sta $E6 + jsr $F3F2 + bit $C080 + .endif + + lda #$2F ; Surl client ready + jsr _serial_putc_direct + + clv ; clear offset-received flag + +ass: lda $A9FF ; Wait for an audio byte + and #HAS_BYTE + beq ass +ads: ldx $A8FF + JUMP_NEXT_9 diff --git a/src/lib/surl/surl_stream_av/surl_stream_av.s b/src/lib/surl/surl_stream_av/surl_stream_av.s index 97d63405..00687928 100644 --- a/src/lib/surl/surl_stream_av/surl_stream_av.s +++ b/src/lib/surl/surl_stream_av/surl_stream_av.s @@ -1,32 +1,48 @@ -_surl_stream_av: ; Entry point - php - sei ; Disable all interrupts +.proc _surl_stream_av + jsr surl_stream_av_send_request + jsr surl_stream_av_setup_ui - pha + ; Ready, send last parameter + lda _video_size + jsr _serial_putc_direct - lda #$00 ; Disable serial interrupts - jsr _simple_serial_set_irq + ; Now wait +@wait_load: + jsr _simple_serial_getc + cmp #SURL_ANSWER_STREAM_LOAD + beq @handle_stream_load + cmp #SURL_ANSWER_STREAM_ART + beq @handle_stream_art + cmp #SURL_ANSWER_STREAM_START + bne @handle_error - pla - ; Setup pointers - jsr setup +@handle_stream_start: + jsr surl_stream_av_prepare_start + jmp @stream_url_done - .ifdef DOUBLE_BUFFER - ; Clear HGR page 2 (page 1 must be done by caller) - bit $C082 - lda #$40 - sta $E6 - jsr $F3F2 - bit $C080 - .endif +@handle_stream_load: + jsr surl_stream_av_handle_preload + jmp @wait_load - lda #$2F ; Surl client ready - jsr _serial_putc_direct +@handle_stream_art: + jsr surl_stream_av_get_art + jmp @wait_load - clv ; clear offset-received flag +@handle_error: + jsr _clrscr + lda #playback_err_str + jsr _cputs + lda #1 + jsr _sleep + jmp @stream_url_done -ass: lda $A9FF ; Wait for an audio byte - and #HAS_BYTE - beq ass -ads: ldx $A8FF - JUMP_NEXT_9 +@stream_url_done: + lda #$00 + jsr pusha + lda _scrh + jsr _set_scrollwindow + lda #$00 + tax + rts +.endproc diff --git a/src/lib/surl/surl_stream_av/surl_stream_av_get_art.s b/src/lib/surl/surl_stream_av/surl_stream_av_get_art.s new file mode 100644 index 00000000..c6fdc3a4 --- /dev/null +++ b/src/lib/surl/surl_stream_av/surl_stream_av_get_art.s @@ -0,0 +1,10 @@ +.proc surl_stream_av_get_art + lda #<$2000 ; Read to HGR page + ldx #>$2000 + jsr pushax + ; AX already the correct length + jsr _surl_read_with_barrier + lda #SURL_CLIENT_READY + sta got_art + jmp _serial_putc_direct +.endproc diff --git a/src/lib/surl/surl_stream_av/surl_stream_av_handle_preload.s b/src/lib/surl/surl_stream_av/surl_stream_av_handle_preload.s new file mode 100644 index 00000000..3b41c5a0 --- /dev/null +++ b/src/lib/surl/surl_stream_av/surl_stream_av_handle_preload.s @@ -0,0 +1,16 @@ +.proc surl_stream_av_handle_preload + jsr update_load_progress + lda KBD + bmi @no_escape + + sta KBDSTRB + and #$7F + cmp #$1B ; Escape? + bne @no_escape + lda #SURL_METHOD_ABORT + bne @send_pong_char +@no_escape: + lda #SURL_CLIENT_READY +@send_pong_char: + jmp _serial_putc_direct +.endproc diff --git a/src/lib/surl/surl_stream_av/surl_stream_av_prepare_start.s b/src/lib/surl/surl_stream_av/surl_stream_av_prepare_start.s new file mode 100644 index 00000000..59336f51 --- /dev/null +++ b/src/lib/surl/surl_stream_av/surl_stream_av_prepare_start.s @@ -0,0 +1,44 @@ +.proc surl_stream_av_prepare_start + lda #SURL_CLIENT_READY + jsr _serial_putc_direct + + ; Check video port on proxy + jsr _simple_serial_getc + cmp #SURL_VIDEO_PORT_NOK + bne @video_ok + ; Inform there's no video available + jsr _clrscr + lda #no_video_str + jsr _cputs + lda #5 + jsr _sleep +@video_ok: + lda got_art + bne @hgr_is_set + + ; If we didn't get art, clear page + lda #<$2000 + ldx #>$2000 + jsr pushax + jsr _bzero + +@hgr_is_set: + .ifdef __APPLE2ENH__ + lda #VIDEOMODE_40COL + jsr _videomode + .endif + jsr _hgr_mixoff + lda #$00 + jsr pusha + lda _scrh + jsr _set_scrollwindow + jsr _clrscr + .ifdef __APPLE2ENH__ + jsr _surl_start_stream_av + lda #VIDEOMODE_80COL + jmp _videomode + .else + jmp _surl_start_stream_av + .endif +.endproc diff --git a/src/lib/surl/surl_stream_av/surl_stream_av_send_request.s b/src/lib/surl/surl_stream_av/surl_stream_av_send_request.s new file mode 100644 index 00000000..dd81588f --- /dev/null +++ b/src/lib/surl/surl_stream_av/surl_stream_av_send_request.s @@ -0,0 +1,51 @@ +.proc surl_stream_av_send_request + ; Backup url + pha + txa + pha + + ; setup surl request headers + jsr push0 ; Push AX 00 + jsr pusha ; Push A 0 + + sta got_art ; init got_art while we got a 0 + + ; URL + pla + tax + pla + jsr pushax + + ; Method + lda #SURL_METHOD_STREAM_AV + + ; Send request + jsr _surl_start_request + + lda _translit_charset + ldx _translit_charset+1 + jsr _simple_serial_puts_nl + + lda #1 ; Monochrome + jsr _serial_putc_direct + + jsr popptr1 ; Pop sub url to ptr1 + lda _enable_subtitles + .assert SUBTITLES_NO = 0, error + beq @no_subs + + ; Do we have a subtitles URL? + ldx ptr1+1 + beq @subs_no_url + + lda #SUBTITLES_URL + jsr _serial_putc_direct + lda ptr1 + jsr _simple_serial_puts_nl + rts +@subs_no_url: + lda #SUBTITLES_AUTO +@no_subs: + jmp _serial_putc_direct ; A=0 if coming from _enable_subtitles=0, + ; AUTO if no URL +.endproc diff --git a/src/lib/surl/surl_stream_av/surl_stream_av_setup_ui.s b/src/lib/surl/surl_stream_av/surl_stream_av_setup_ui.s new file mode 100644 index 00000000..a09d7c58 --- /dev/null +++ b/src/lib/surl/surl_stream_av/surl_stream_av_setup_ui.s @@ -0,0 +1,31 @@ +.proc surl_stream_av_setup_ui + ; Clear screen, setup HGR mix with scrollwindow + jsr _clrscr + lda #20 + jsr pusha + lda _scrh + jsr _set_scrollwindow + + lda #1 + jsr _init_hgr + jsr _hgr_mixon + jsr _clrscr + + ; Clear text page 2 + lda #<$0800 + ldx #>$0800 + jsr pushax + + lda #($20|$80) ; with non-inverse spaces + jsr pusha0 + + ; 1kB + lda #<$400 + ldx #>$400 + jsr _memset + + ; Show controls + lda #controls_str + jmp _cputs +.endproc diff --git a/src/lib/surl/surl_stream_av/update_load_progress.s b/src/lib/surl/surl_stream_av/update_load_progress.s new file mode 100644 index 00000000..6fed28bb --- /dev/null +++ b/src/lib/surl/surl_stream_av/update_load_progress.s @@ -0,0 +1,45 @@ +.proc update_load_progress + ; Go to correct place + lda #11 + jsr pusha + lda #0 + jsr _gotoxy + + ; Send ready + lda #SURL_CLIENT_READY + jsr _serial_putc_direct + + ; Get ETA + jsr _simple_serial_getc + cmp #$FF + beq @opening + cmp #$FE + beq @long +@secs: + ; < 254 means the estimate is about A<<3 seconds + pha + lda #eta_secs_str + jsr pushax + pla + ldx #$00 + jsr shlax3 + jsr pushax + ldy #$04 + bne @print +@long: + ; 254 means more than 30 minutes estimated + lda #eta_long_str + bne @print2 +@opening: + ; 255 means proxy is still opening the stream + lda #eta_open_str +@print2: + jsr pushax + ldy #$02 + +@print: + jmp _cprintf +.endproc diff --git a/src/mastodon/Makefile b/src/mastodon/Makefile index bd7a4c95..8cfecf1e 100644 --- a/src/mastodon/Makefile +++ b/src/mastodon/Makefile @@ -71,7 +71,6 @@ mastoimg_SOURCES := \ ../lib/file_select.c \ ../lib/strsplit.c \ ../lib/realloc_safe.c \ - ../lib/hgr.c \ ../lib/dgets.c ifdef IIGS @@ -82,8 +81,7 @@ mastoimg_CC65SOURCES := \ else mastoimg_CC65SOURCES := \ - ../lib/surl/surl_stream_av/$(CPU).s \ - ../lib/surl/surl_stream_av/stream_url.c + ../lib/surl/surl_stream_av/$(CPU).s endif @@ -99,6 +97,7 @@ mastoimg_CC65SOURCES := \ ../lib/asm/path_helper.s \ ../lib/asm/clrzone.s \ ../lib/asm/malloc0.s \ + ../lib/asm/hgr.s \ ../lib/FVTABZ.s \ ../lib/extrazp.s \ ../lib/surl/surl_wait_for_stream.c \ @@ -153,6 +152,7 @@ GCCSOURCES := \ ../lib/c/clrzone.c \ ../lib/c/path_helper.c \ ../lib/c/malloc0.c \ + ../lib/c/hgr.c \ ../lib/c/atoc.c \ ../lib/extended_conio.c \ ../lib/strtrim.c \ @@ -171,13 +171,11 @@ mastodon_CLCFLAGS = $(CLCFLAGS) -C ../../config/apple2enh-rtonce.cfg mastocli_CLCFLAGS = $(CLCFLAGS) -C ../../config/apple2enh-rtonce.cfg ifdef OLDII mastoimg_CLCFLAGS = $(CLCFLAGS) -C ../../config/apple2enh-mastoimg-6502.cfg \ - -DSTART_ADDR=0x3DA0 --start-addr 0x3DA0 \ - -DSTREAM_URL_SEGMENT='"LC"' + -DSTART_ADDR=0x3EA0 --start-addr 0x3EA0 else mastoimg_CLCFLAGS = $(CLCFLAGS) -C ../../config/apple2enh-mastoimg-65c02.cfg \ -DDOUBLE_BUFFER --asm-define DOUBLE_BUFFER \ - -DSTART_ADDR=0x5DA0 --start-addr 0x5DA0 \ - -DSTREAM_URL_SEGMENT='"LC"' + -DSTART_ADDR=0x5EA0 --start-addr 0x5EA0 endif mastowrite_CLCFLAGS = $(CLCFLAGS) -C ../../config/apple2enh-rtonce.cfg -DDGETS_MULTILINE diff --git a/src/mastodon/api/account.c b/src/mastodon/api/account.c index 7029650d..2c317c62 100644 --- a/src/mastodon/api/account.c +++ b/src/mastodon/api/account.c @@ -8,8 +8,6 @@ #include "strsplit.h" #include "api.h" -#define BUF_SIZE 255 - #ifdef __CC65__ #ifdef SURL_TO_LANGCARD #pragma code-name (push, "LC") diff --git a/src/mastodon/api/media.c b/src/mastodon/api/media.c index 64fe0c79..22cae698 100644 --- a/src/mastodon/api/media.c +++ b/src/mastodon/api/media.c @@ -10,16 +10,16 @@ #include "api.h" #ifdef __CC65__ -#pragma code-name (push, "LOWCODE") +#pragma code-name (push, "LC") #endif #define IMG_BUF_SIZE 2048 static char img_buf[IMG_BUF_SIZE]; -#ifdef USE_HGR2 - #define NUMCOLS 40 +#ifdef __APPLE2ENH__ +#define NUMCOLS 80 #else - #define NUMCOLS 80 +#define NUMCOLS 40 #endif static media *media_new_from_json(char *base_selector, char *description_selector) { @@ -117,11 +117,11 @@ media *api_get_status_media(char *id) { id); } +#ifdef __CC65__ +#pragma code-name (pop) +#endif + media *api_get_account_media(char *id) { return get_media(ACCOUNTS_ENDPOINT, ".id,.avatar_static,.id,.header_static", NULL, id); } - -#ifdef __CC65__ -#pragma code-name (pop) -#endif diff --git a/src/mastodon/api/oauth.c b/src/mastodon/api/oauth.c index 81e30593..d541fa36 100644 --- a/src/mastodon/api/oauth.c +++ b/src/mastodon/api/oauth.c @@ -9,18 +9,13 @@ #include "strsplit.h" #include "dputs.h" #include "extended_conio.h" +#include "common.h" /* This is heavily based on screen-scraping and not very solid. * Maybe using https://github.com/lexbor/lexbor proxy-side would be * better. */ -#ifdef __CC65__ -#pragma code-name (push, "LOWCODE") -#endif - -#define BUF_SIZE 255 - #define LOGIN_URL "/auth/sign_in" #define REGISTER_URL "/api/v1/apps" #define REDIRECT_URI "urn:ietf:wg:oauth:2.0:oob" @@ -67,6 +62,10 @@ static char *get_csrf_token(char *body, size_t buf_size) { return token; } +#ifdef __CC65__ +#pragma code-name (push, "LC") +#endif + static char *get_oauth_code(char *body) { char *w, *token = NULL; size_t len; @@ -316,6 +315,10 @@ int do_login(void) { } +#ifdef __CC65__ +#pragma code-name (pop) +#endif + static char *prepare_app_register_post(void) { char *data; diff --git a/src/mastodon/cli/compose.c b/src/mastodon/cli/compose.c index 1573bc34..c4a72bc9 100644 --- a/src/mastodon/cli/compose.c +++ b/src/mastodon/cli/compose.c @@ -559,6 +559,7 @@ static void compose_toot(char *initial_buf) { int main(int argc, char **argv) { char *params; + char *text = NULL; surl_user_agent = "Mastodon for Apple II / "VERSION; @@ -619,7 +620,15 @@ int main(int argc, char **argv) { } } } - } else { + } else if (argc == 5) { + text = malloc(strlen(argv[4])+2); + if (text) { + text[0] = arobase; + strcpy(text+1, argv[4]); + while (strchr(text, '@')) { + *(strchr(text, '@')) = arobase; + } + } ref_status = NULL; } @@ -634,8 +643,12 @@ int main(int argc, char **argv) { compose_toot(orig_status); free(orig_status); } else { - compose_toot(""); + if (text == NULL) { + text = strdup(""); + } + compose_toot(text); } + free(text); set_hscrollwindow(0, scrw); params = malloc0(127); diff --git a/src/mastodon/cli/img.c b/src/mastodon/cli/img.c index b3a78d27..128e8ae0 100644 --- a/src/mastodon/cli/img.c +++ b/src/mastodon/cli/img.c @@ -15,10 +15,6 @@ * along with this program. If not, see . */ -#ifdef __CC65__ -#pragma code-name (push, "LC") -#endif - #include #include #include @@ -37,7 +33,6 @@ #include "common.h" #include "path_helper.h" #include "dgets.h" -#include "surl/surl_stream_av/stream_url.h" char *instance_url; char *oauth_token; @@ -106,7 +101,7 @@ static void stream_msg(char *msg) { cputs(msg); } -int stream_url(char *url, char *unused) { +int __fastcall__ surl_stream_av(char *unused, char *url) { #ifdef __APPLE2ENH__ videomode(VIDEOMODE_40COL); #endif @@ -240,7 +235,7 @@ int main(int argc, char **argv) { #ifdef __CC65__ bzero((char *)HGR_PAGE, HGR_LEN); clrscr(); - stream_url(m->media_url[0], NULL); + surl_stream_av(NULL, m->media_url[0]); clrscr(); init_text(); #endif @@ -292,10 +287,9 @@ int main(int argc, char **argv) { } #ifdef __CC65__ -#pragma code-name (pop) +#pragma code-name (push, "LC") #endif - static void save_image(void) { unsigned char prev_legend = legend; char buf[FILENAME_MAX + 1]; @@ -347,3 +341,6 @@ static void save_image(void) { if (!prev_legend) toggle_legend(0); } +#ifdef __CC65__ +#pragma code-name (pop) +#endif diff --git a/src/mastodon/cli/login.c b/src/mastodon/cli/login.c index 96c4507d..8b92762d 100644 --- a/src/mastodon/cli/login.c +++ b/src/mastodon/cli/login.c @@ -37,8 +37,6 @@ #include "runtime_once_clean.h" #include "config.h" -#define BUF_SIZE 255 - unsigned char scrw, scrh; char *instance_url = NULL; char *client_id = NULL; diff --git a/src/mastodon/cli/tl.c b/src/mastodon/cli/tl.c index f1bb3378..17c7f4f7 100644 --- a/src/mastodon/cli/tl.c +++ b/src/mastodon/cli/tl.c @@ -24,7 +24,9 @@ #include "scrollwindow.h" #include "runtime_once_clean.h" -#define BUF_SIZE 255 +#ifdef __CC65__ +#pragma code-name (push, "LC") +#endif #pragma register-vars(push, on) @@ -182,6 +184,10 @@ static void item_free(list *l, char i) { } } +#ifdef __CC65__ +#pragma code-name (pop) +#endif + static item *item_get(list *l, char i, char full) { if (l->kind == SHOW_NOTIFICATIONS) { return (item *)api_get_notification(l->ids[i]); @@ -1307,7 +1313,10 @@ static void cli(void) { launch_command("mastodon", "conf", NULL, NULL); /* we're never coming back */ case COMPOSE: - launch_command("mastowrite", NULL, NULL, NULL); + if (current_list->account) + launch_command("mastowrite", current_list->account->acct, NULL, NULL); + else + launch_command("mastowrite", NULL, NULL, NULL); /* we're never coming back */ case REPLY: if (disp_status) diff --git a/src/quicktake/Makefile b/src/quicktake/Makefile index f988da7a..f4078839 100644 --- a/src/quicktake/Makefile +++ b/src/quicktake/Makefile @@ -49,7 +49,6 @@ slowtake_SOURCES := \ ../lib/realloc_safe.c \ ../lib/file_select.c \ ../lib/progress_bar.c \ - ../lib/hgr.c \ ../lib/hgr_addrs.c \ $(debug_SOURCES) @@ -62,6 +61,7 @@ slowtake_CC65SOURCES := \ ../lib/asm/scrollwindow.s \ ../lib/asm/path_helper.s \ ../lib/asm/malloc0.s \ + ../lib/asm/hgr.s \ ../lib/dputc.s \ ../lib/scroll.s \ ../lib/FVTABZ.s \ @@ -78,6 +78,7 @@ slowtake_GCCSOURCES := \ ../lib/serial/c/serial_control.c \ ../lib/c/scrollwindow.c \ ../lib/c/malloc0.c \ + ../lib/c/hgr.c \ ../lib/tgi_sdl.c \ ../lib/tgi_fastline.c diff --git a/src/quicktake/qt-edit-image.c b/src/quicktake/qt-edit-image.c index 5f663425..9cb01352 100644 --- a/src/quicktake/qt-edit-image.c +++ b/src/quicktake/qt-edit-image.c @@ -419,7 +419,7 @@ static uint8 reedit_image(const char *ofname, uint16 src_width) { : dither_alg == DITHER_SIERRA ? "Sierra Lite" : "None"); c = tolower(cgetc()); #ifdef __CC65__ - if (!hgr_mix_is_on()) { + if (!hgr_mix_is_on) { hgr_mixon(); } else #endif diff --git a/src/surl-server/surl_protocol.h b/src/surl-server/surl_protocol.h index 69c66474..54b01498 100644 --- a/src/surl-server/surl_protocol.h +++ b/src/surl-server/surl_protocol.h @@ -3,7 +3,7 @@ /* Update in .inc too! */ #define SURL_PROTOCOL_VERSION 21 -#define VERSION "21.0.0" +#define VERSION "21.0.1" #define SURL_CLIENT_READY 0x2F #define HGR_LEN 8192U diff --git a/src/wozamp/Makefile b/src/wozamp/Makefile index de9824f1..7bf41eed 100644 --- a/src/wozamp/Makefile +++ b/src/wozamp/Makefile @@ -17,7 +17,6 @@ upload_subdir := CC65_TARGET := apple2 BUILD_VIDEOPLAY := 1 STREAMER_VER := 6502 -STREAM_URL_SEGMENT := "CODE" VIDEOPLAY_START_ADDR := 0x1D00 EMBED_RBROWSER := EXTERNAL_RBROWSER := rbrowser.bin @@ -29,7 +28,6 @@ CC65_TARGET = apple2enh trgt = apple2c0 BUILD_VIDEOPLAY := 1 STREAMER_VER := 65c02 -STREAM_URL_SEGMENT := "CODE" VIDEOPLAY_START_ADDR := 0x1D00 EMBED_RBROWSER := radio-browser.c ../lib/surl/asm/surl_get_json.s EXTERNAL_RBROWSER := @@ -51,7 +49,6 @@ wozamp_SOURCES := \ wozamp_CL65SOURCES = \ ../lib/surl/surl_stream_audio/$(STREAMER_VER).s \ - ../lib/hgr.c \ ../lib/serial/asm/simple_serial.s \ ../lib/serial/asm/simple_serial_io.s \ ../lib/serial/asm/simple_serial_configure.s \ @@ -63,6 +60,7 @@ wozamp_CL65SOURCES = \ ../lib/asm/scrollwindow.s \ ../lib/asm/path_helper.s \ ../lib/asm/malloc0.s \ + ../lib/asm/hgr.s \ ../lib/dputc.s \ ../lib/scroll.s \ ../lib/FVTABZ.s \ @@ -90,7 +88,6 @@ rbrowser_SOURCES := \ rbrowser_CL65SOURCES = \ ../lib/surl/surl_stream_audio/$(STREAMER_VER).s \ - ../lib/hgr.c \ ../lib/serial/asm/simple_serial.s \ ../lib/serial/asm/simple_serial_io.s \ ../lib/serial/$(serial_hw)/common.s \ @@ -102,6 +99,7 @@ rbrowser_CL65SOURCES = \ ../lib/asm/scrollwindow.s \ ../lib/asm/path_helper.s \ ../lib/asm/malloc0.s \ + ../lib/asm/hgr.s \ ../lib/dputc.s \ ../lib/dputs.s \ ../lib/scroll.s \ @@ -130,9 +128,7 @@ rbrowser_CLCFLAGS = -t $(CC65_TARGET) \ ifdef BUILD_VIDEOPLAY videoplay_SOURCES := \ ../lib/surl/surl_stream_av/$(STREAMER_VER).s \ - ../lib/surl/surl_stream_av/stream_url.c \ videoplay.c \ - ../lib/hgr.c \ ../lib/FVTABZ.s \ ../lib/serial/asm/simple_serial.s \ ../lib/serial/asm/simple_serial_io.s \ @@ -144,12 +140,12 @@ videoplay_SOURCES := \ ../lib/asm/scrollwindow.s \ ../lib/asm/path_helper.s \ ../lib/asm/malloc0.s \ + ../lib/asm/hgr.s \ ../lib/fastirq$(iigs_suffix).s \ ../lib/extrazp.s videoplay_CLCFLAGS = -t $(CC65_TARGET) \ -DDOUBLE_BUFFER --asm-define DOUBLE_BUFFER \ - -DSTREAM_URL_SEGMENT='$(STREAM_URL_SEGMENT)' \ -I ../lib \ -Wl -D,__STACKSIZE__=0x0400 -C ../../config/apple2enh-wozamp-videoplay.cfg \ -vm -m videoplay.map $(USE_LANGCARD) -O --start-addr $(VIDEOPLAY_START_ADDR) diff --git a/src/wozamp/videoplay.c b/src/wozamp/videoplay.c index 154be9db..7c6d5143 100644 --- a/src/wozamp/videoplay.c +++ b/src/wozamp/videoplay.c @@ -13,7 +13,6 @@ #include "config.h" #include "splash-video.h" #include "scrollwindow.h" -#include "surl/surl_stream_av/stream_url.h" char *translit_charset; char monochrome = 1; @@ -65,7 +64,7 @@ int main(void) { } reopen_start_device(); - stream_url(url, NULL); + surl_stream_av(NULL, url); out: clrscr(); diff --git a/src/woztubes/Makefile b/src/woztubes/Makefile index e84b6605..a84407b1 100644 --- a/src/woztubes/Makefile +++ b/src/woztubes/Makefile @@ -13,7 +13,7 @@ suffix := upload_subdir := CC65_TARGET := apple2 STREAMER_VER := 6502 -START_ADDR := 0xD3A +START_ADDR := 0x113A else serial_hw := acia iigs_suffix := @@ -21,7 +21,7 @@ iigs_CFLAGS := CC65_TARGET = apple2enh trgt = apple2c0 STREAMER_VER := 65c02 -START_ADDR := 0xD3A +START_ADDR := 0x113A endif endif @@ -36,11 +36,9 @@ GCCCFLAGS = -g -O0 -DCONF_FILE_PATH=\"/etc/a2tools/tty.conf\" \ woztubes_SOURCES := \ ../lib/surl/surl_stream_av/$(STREAMER_VER).s \ - ../lib/surl/surl_stream_av/stream_url.c \ main.c \ video_providers.c \ config.c \ - ../lib/hgr.c \ ../lib/scroll.s \ ../lib/dputc.s \ ../lib/dgets.c \ @@ -58,6 +56,7 @@ woztubes_SOURCES := \ ../lib/asm/path_helper.s \ ../lib/asm/clrzone.s \ ../lib/asm/malloc0.s \ + ../lib/asm/hgr.s \ ../lib/surl/surl_ping.c \ ../lib/extrazp.s \ ../lib/citoa.s \ @@ -83,7 +82,6 @@ woztubes_CLCFLAGS = -t $(CC65_TARGET) -I ../lib \ -DBUF_1K_ADDR=0x800 -DBUF_1K_SIZE=0x3FF \ -DBUF_8K_ADDR=0x4000 -DBUF_8K_SIZE=0x1FFF \ -DDOUBLE_BUFFER --asm-define DOUBLE_BUFFER \ - -DSTREAM_URL_SEGMENT='"LOWCODE"' \ -Wl -D,__STACKSIZE__=0x0400 -C ../../config/apple2enh-woztubes.cfg \ -vm -m woztubes.map $(USE_LANGCARD) -O --start-addr $(START_ADDR) diff --git a/src/woztubes/main.c b/src/woztubes/main.c index b6be9e8e..12650d51 100644 --- a/src/woztubes/main.c +++ b/src/woztubes/main.c @@ -40,7 +40,6 @@ #include "splash.h" #include "malloc0.h" #include "citoa.h" -#include "surl/surl_stream_av/stream_url.h" #include "video_providers.h" char *url = NULL; @@ -243,7 +242,7 @@ static void load_video(char *host, InstanceTypeId instance_type, char *id) { } } - stream_url(video_url, captions_url); + surl_stream_av(captions_url, video_url); set_scrollwindow(20, scrh); #ifdef __APPLE2ENH__