11use core:: alloc:: Allocator ;
22use core:: pin:: Pin ;
33use std:: ops:: Not ;
4+ use bitflags:: bitflags;
45use gc_arena:: Collect ;
6+ use p8rs_macros:: TransparentRef ;
57use p8rs_piccolo:: { BoxSequence , Callback , CallbackReturn , Context , Error , Execution , RuntimeError , RuntimeRef , Sequence , SequencePoll , Stack , String , Value } ;
68use p8rs_types:: p8num:: P8Num ;
7- use p8rs_types:: p8scii:: Display ;
89use crate :: vm:: font:: Font ;
910use crate :: vm:: memory:: machine_state:: { MiscChipsetFeatureFlags , PrintDefaultsFlags } ;
1011use crate :: vm:: memory:: painter:: CallbackResult ;
@@ -55,12 +56,7 @@ pub fn install_pico8_print<A: Allocator + 'static>(ctx: Context) {
5556 let flags = * rt. memory . machine_state ( ) . print_defaults ( ) . flags ( ) ;
5657
5758 if y. is_none ( ) {
58- let ( line_height, font_height) = get_line_height ( rt, flags) ;
59- println ! ( "print({}) - cursor: {:?}" , text, rt. get_cursor_position( ) ) ;
60- println ! ( "print: scrolling in case line would not fit, line_height={}, font_height={}" , line_height, font_height) ;
6159 handle_newline ( rt, NewlineRequest :: MakeSpaceBeforePrint , flags, y. is_some ( ) ) ;
62- } else {
63- println ! ( "print({}, {}, {}) - cursor: {:?}" , text, x. unwrap( ) , y. unwrap( ) , rt. get_cursor_position( ) ) ;
6460 }
6561
6662 Ok ( CallbackReturn :: Sequence ( BoxSequence :: new ( ctx. mutation ( ) , PrintSeq {
@@ -98,10 +94,33 @@ enum EscapeSequenceAction {
9894 ModifyFlags ( PrintDefaultsFlags ) ,
9995}
10096
97+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , TransparentRef ) ]
98+ #[ repr( transparent) ]
99+ pub struct PrintStateFlags ( u16 ) ;
100+
101+ bitflags ! {
102+ impl PrintStateFlags : u16 {
103+ // const ENABLE = 1 << 0;
104+ const PADDING = 1 << 1 ;
105+ const WIDE = 1 << 2 ;
106+ const TALL = 1 << 3 ;
107+ const SOLID_BG = 1 << 4 ;
108+ const INVERT = 1 << 5 ;
109+ const DOTTY = 1 << 6 ;
110+ const CUSTOM_FONT = 1 << 7 ;
111+
112+ const PINBALL_DOTTY = 1 << 8 ;
113+ const WRAP = 1 << 9 ;
114+ const SCROLL = 1 << 10 ;
115+ const END_NEWLINE = 1 << 11 ;
116+ // TODO: finish internal print state
117+
118+ const _ = !0 ;
119+ }
120+ }
121+
101122fn screen_shift_up_exact ( rt : & mut Runtime , shift : u8 ) {
102- println ! ( "screen_shift_up_exact: scrolling, shift={}" , shift) ;
103123 if rt. memory . machine_state ( ) . misc_chipset_flags ( ) . contains ( MiscChipsetFeatureFlags :: NO_PRINT_SCROLL ) {
104- println ! ( "screen_shift_up_exact: jk actually NO_PRINT_SCROLL" ) ;
105124 return ;
106125 }
107126
@@ -118,8 +137,6 @@ enum NewlineRequest {
118137}
119138
120139fn handle_newline ( rt : & mut Runtime , request : NewlineRequest , flags : PrintDefaultsFlags , y_passed : bool ) {
121- println ! ( "handle_newline({:?})" , request) ;
122-
123140 let ( line_height, font_height) = get_line_height ( rt, flags) ;
124141
125142 let ( reset_x, align_shift, advance_y, considered_height) = match request {
@@ -146,7 +163,6 @@ fn handle_newline(rt: &mut Runtime, request: NewlineRequest, flags: PrintDefault
146163 if align_shift && shift < font_height {
147164 shift = font_height;
148165 }
149- println ! ( "handle_newline - shifting - new_y: {}, max_y: {}, shift: {}" , new_y, max_y, shift) ;
150166 screen_shift_up_exact ( rt, shift) ;
151167 }
152168 }
@@ -185,17 +201,14 @@ fn execute_escape_sequence<'gc>(_ctx: Context<'gc>, rt: &mut Runtime, flags: Pri
185201 }
186202 b'-' => {
187203 if let Some ( flag) = escape_to_print_flags ( bytes[ 2 ] ) {
188- println ! ( "Escape: ^- {}" , Display ( bytes) ) ;
189204 EscapeSequenceAction :: ModifyFlags ( flags & flag. not ( ) )
190205 } else {
191- println ! ( "Escape UNPARSED: {}" , Display ( bytes) ) ;
192206 debug ! ( "unparsed sequence {:?}" , bytes) ;
193207 EscapeSequenceAction :: Nop
194208 }
195209 } ,
196210 _ => {
197211 if let Some ( flag) = escape_to_print_flags ( arg) {
198- println ! ( "Escape parsed: ^ {}" , Display ( bytes) ) ;
199212 return Ok ( EscapeSequenceAction :: ModifyFlags ( flags | flag | PrintDefaultsFlags :: ENABLE ) )
200213 }
201214 debug ! ( "Unimplemented escape sequence! {:?}" , bytes) ;
0 commit comments