2016-12-28 20:32:00 +00:00
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
2020-04-28 16:02:09 +00:00
// Copyright (C) 1998-2020 Marco Baye
2012-02-27 21:14:46 +00:00
// Have a look at "acme.c" for further info
//
2016-02-21 12:58:22 +00:00
// Output stuff (FIXME - split into outbuf, outfile/format and vcpu parts)
2012-02-27 21:14:46 +00:00
# ifndef output_H
# define output_H
# include <stdio.h>
# include "config.h"
2014-03-11 14:22:32 +00:00
// constants
2012-02-27 21:14:46 +00:00
# define MEMINIT_USE_DEFAULT 256
2014-12-03 22:18:06 +00:00
// segment flags
# define SEGMENT_FLAG_OVERLAY (1u << 0) // do not warn about this segment overwriting another one
# define SEGMENT_FLAG_INVISIBLE (1u << 1) // do not warn about other segments overwriting this one
2012-02-27 21:14:46 +00:00
2014-03-11 14:22:32 +00:00
// current CPU state
2020-04-28 16:02:09 +00:00
// FIXME - move vcpu struct definition to .c file and change other .c files' accesses to fn calls. then replace "struct number" with minimized version.
2014-03-11 14:22:32 +00:00
struct vcpu {
const struct cpu_type * type ; // current CPU type (default 6502) (FIXME - move out of struct again?)
2020-04-28 16:02:09 +00:00
struct number pc ; // current program counter (pseudo value)
2014-03-11 14:22:32 +00:00
int add_to_pc ; // add to PC after statement
2020-05-06 11:40:06 +00:00
boolean a_is_long ;
boolean xy_are_long ;
2014-03-11 14:22:32 +00:00
} ;
2020-05-22 20:55:36 +00:00
// buffer to hold outer state while parsing "pseudopc" block
struct pseudopc {
intval_t offset ;
int flags ;
} ;
2014-03-11 14:22:32 +00:00
// variables
2016-02-21 12:58:22 +00:00
extern struct vcpu CPU_state ; // current CPU state FIXME - restrict visibility to .c file
2014-03-11 14:22:32 +00:00
2012-02-27 21:14:46 +00:00
// Prototypes
2014-03-10 00:17:10 +00:00
// clear segment list and disable output
2017-10-21 20:23:22 +00:00
//TODO - does this belong to outbuf stuff?
2014-03-10 00:17:10 +00:00
extern void Output_passinit ( void ) ;
2017-10-21 20:23:22 +00:00
// outbuf stuff:
// alloc and init mem buffer (done later)
extern void Output_init ( signed long fill_value ) ;
2017-10-21 19:59:56 +00:00
// skip over some bytes in output buffer without starting a new segment
// (used by "!skip", and also called by "!binary" if really calling
// Output_byte would be a waste of time)
extern void output_skip ( int size ) ;
2012-02-27 21:14:46 +00:00
// Send low byte of arg to output buffer and advance pointer
2017-10-21 19:59:56 +00:00
// FIXME - replace by output_sequence(char *src, size_t size)
2012-02-27 21:14:46 +00:00
extern void ( * Output_byte ) ( intval_t ) ;
2017-10-21 19:59:56 +00:00
// define default value for empty memory ("!initmem" pseudo opcode)
// returns zero if ok, nonzero if already set
extern int output_initmem ( char content ) ;
2017-10-21 20:23:22 +00:00
// move elsewhere:
2012-02-27 21:14:46 +00:00
// Output 8-bit value with range check
2014-12-03 22:18:06 +00:00
extern void output_8 ( intval_t ) ;
2016-02-16 23:11:04 +00:00
// Output 16-bit value with range check big-endian
extern void output_be16 ( intval_t ) ;
// Output 16-bit value with range check little-endian
2014-12-03 22:18:06 +00:00
extern void output_le16 ( intval_t ) ;
2016-02-16 23:11:04 +00:00
// Output 24-bit value with range check big-endian
extern void output_be24 ( intval_t ) ;
// Output 24-bit value with range check little-endian
2014-12-03 22:18:06 +00:00
extern void output_le24 ( intval_t ) ;
2016-02-16 23:11:04 +00:00
// Output 32-bit value (without range check) big-endian
extern void output_be32 ( intval_t ) ;
// Output 32-bit value (without range check) little-endian
2014-12-03 22:18:06 +00:00
extern void output_le32 ( intval_t ) ;
2017-10-21 20:23:22 +00:00
// outfile stuff:
2014-12-03 22:18:06 +00:00
// try to set output format held in DynaBuf. Returns zero on success.
2016-02-21 12:58:22 +00:00
extern int outputfile_set_format ( void ) ;
extern const char outputfile_formats [ ] ; // string to show if outputfile_set_format() returns nonzero
2014-12-03 22:18:06 +00:00
// if file format was already chosen, returns zero.
// if file format isn't set, chooses CBM and returns 1.
2016-02-21 12:58:22 +00:00
extern int outputfile_prefer_cbm_format ( void ) ;
2014-12-03 22:18:06 +00:00
// try to set output file name held in DynaBuf. Returns zero on success.
2016-02-21 12:58:22 +00:00
extern int outputfile_set_filename ( void ) ;
2012-02-27 21:14:46 +00:00
// write smallest-possible part of memory buffer to file
extern void Output_save_file ( FILE * fd ) ;
2014-03-10 00:17:10 +00:00
// change output pointer and enable output
extern void Output_start_segment ( intval_t address_change , int segment_flags ) ;
2012-02-27 21:14:46 +00:00
// Show start and end of current segment
extern void Output_end_segment ( void ) ;
2017-12-22 22:55:36 +00:00
extern char output_get_xor ( void ) ;
extern void output_set_xor ( char xor ) ;
2012-02-27 21:14:46 +00:00
2016-02-21 12:58:22 +00:00
// set program counter to defined value (TODO - allow undefined!)
2014-03-11 14:22:32 +00:00
extern void vcpu_set_pc ( intval_t new_pc , int flags ) ;
// get program counter
2020-04-28 16:02:09 +00:00
extern void vcpu_read_pc ( struct number * target ) ;
2014-03-11 14:22:32 +00:00
// get size of current statement (until now) - needed for "!bin" verbose output
extern int vcpu_get_statement_size ( void ) ;
// adjust program counter (called at end of each statement)
extern void vcpu_end_statement ( void ) ;
2020-05-22 20:55:36 +00:00
// start offset assembly
extern void pseudopc_start ( struct pseudopc * buffer , struct number * new_pc ) ;
// end offset assembly
extern void pseudopc_end ( struct pseudopc * buffer ) ;
2014-03-11 14:22:32 +00:00
2012-02-27 21:14:46 +00:00
# endif